Fork without wait

Fork without wait

Post by Ron Isaacs » Wed, 09 Aug 1995 04:00:00



[ Article crossposted from comp.lang.c ]
[ Author was Ron Isaacson ]
[ Posted on 8 Aug 1995 06:18:58 GMT ]

I'm trying to fork a child process (which execve's itself to something
else) without having the parent wait for it, under any circumstances.
This seems like a relatively simple thing, but I seem to be having
some trouble.

Some of my code:

  if (fork() == 0) {
    setsid();

    [ set "args"... ]

    execve (args[0], args, NULL);
    exit (0);
  } else {

    [ print some stuff... ]

    exit (0);
  }

The "print some stuff" happens immediately after the child is spawned,
but the parent doesn't really exit until after the child does. I even
put setsid() in there to disassociate the child from the parent (at
least, I thought that's what it did) but it doesn't work.

Any advice greatly appreciated. Thank you very much!


        http://www.seas.upenn.edu/~isaacson/

--


        http://www.seas.upenn.edu/~isaacson/

 
 
 

Fork without wait

Post by Ron Isaacs » Thu, 10 Aug 1995 04:00:00


: The "print some stuff" happens immediately after the child is spawned,
: but the parent doesn't really exit until after the child does.

It seems I left out a crucial piece of information. This program is
running as a CGI script under the Netscape Communications server. The
child is some processing that should be started in the background, and
the "print some stuff" is a redirect. Apparently, it's not the parent
waiting on the child, it's Netscape waiting on both of them before it
will return the redirect to the client.

I tried all sorts of tricks with process groups and SIGCHLD's, but
could not get Netscape to stop waiting. I finally tried flushing and
closing the parent's stdout and then SIGTERM'ing the parent's parent
(ie, the waiting netscape process) and that did the trick. I'm not
sure if killing your own parent is a safe thing to do, especially when
you have a child running, but it seems to work. If anybody has any
better ideas, I'd appreciate hearing them!


        http://www.seas.upenn.edu/~isaacson/