LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   I want to start a prog from another prog but not as child (http://www.linuxquestions.org/questions/programming-9/i-want-to-start-a-prog-from-another-prog-but-not-as-child-325956/)

grupoapunte 05-22-2005 12:57 PM

I want to start a prog from another prog but not as child
 
Hi, I need to know if theres a way to start a program from another program without using fork() the thing is i dont want that the new program apears like child of the first one, both programs execute in a console, and the program i want to start has no usr interface (it runs in background), I have already tryed this in my code but didnt work:

sprintf(eHab->cBuffIO, "./Persona %s %hd no", eHab->cIp, eHab->usPuerto);
system(eHab->cBuffIO);

./Persona is the program, and eHab->cIp, eHab->usPuerto are the params

Thanks, Damian.

eddiebaby1023 05-22-2005 02:40 PM

Use one of the exec(3) family of system calls. man 3 exec for details. Ask here again if you need clarification of what you've read.

grupoapunte 05-22-2005 03:07 PM

In first place thanks for your help, I know about those functions, cant use them, sry I forgot to say that I need both programs working, the problem is that those functions remplace the program that calls it by the new prog thats being executed, the way to avoid that is using fork() but the new program will apear as a child, and I cant do that.

If you know about any other way to do it, or if thers no posible way, please tell me.

Thanks again Damian.

randyding 05-22-2005 09:14 PM

You must then fork() twice. The first fork starts a second fork and then the first one terminates, causing the process to be owned by init process.

eddiebaby1023 05-23-2005 06:12 PM

Quote:

the new program will apear as a child, and I cant do that.
All processes have a parent process so they all appear to run as a child. Or do you mean it mustn't be owned by the spawning process (in which case randyding's reply is your answer)? Any particular reason - I'm intrigued?

Hko 05-23-2005 06:37 PM

You could fork() the program, then call daemon(0,0).
After daemon(0,0) the program will not have any terminal to talk to anymore though.


All times are GMT -5. The time now is 02:21 AM.