1748036 Members
4879 Online
108757 Solutions
New Discussion юеВ

forking a new process

 
SOLVED
Go to solution
siaemic
Advisor

forking a new process

Inside a C program, how can I launch a new application and let it running even if parent process die without becoming a zombie?
Does the new application get a parent pid equal to 1 ?
6 REPLIES 6
harry d brown jr
Honored Contributor
Solution

Re: forking a new process

man exec

live free or die
harry
Live Free or Die
Rainer von Bongartz
Honored Contributor

Re: forking a new process



Choose one of the following

execl(), execle(), execlp(), execv(), execve(), execvp()

Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Dietmar Konermann
Honored Contributor

Re: forking a new process

I usually do things like this...

[...]

if (signal (SIGCHLD, SIG_IGN) == -1)
perror("signal");

if ( (pid = fork()) < 0)
perror("fork");
else if (pid == 0) { /* child */
setsid(); /* become leader */
execlp ("cmd", "arg0", "arg1", (char*) 0); /* run your prg */
perror ("execlp");
}

[...]
/* parent continues */
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Wodisch
Honored Contributor

Re: forking a new process

Hi,

in addition you'll have to set the SIG_CHLD to *ignore* BEFORE you call "fork(2)"!

HTH,
Wodisch
Dietmar Konermann
Honored Contributor

Re: forking a new process

Hmm, Wodisch.... do I miss something? I call signal() before fork()ing.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Wodisch
Honored Contributor

Re: forking a new process

Dietmar,

you are right - and I was blind :-(