in reply to explain my fork

fork returns twice, once in the parent and once in the child, with zero in the child and the child's PID in the parent. Both processes continue running at the same time (or as close to the same time as your hardware and OS allow). To do what you're describing, normally the CGI script will fork a child process; the child will often fork again, to fully dissociate itself from the parent process, close any open file descriptors, then do its thing in the background, perhaps with exec. In the meantime, the parent is finishing up sending output to the client, then exiting or accepting another request.

An easy way to do what you want without using fork and exec is to do system('some_cmd &').

Update: Thanks, wirrwarr, I didn't realize that using an ampersand to start a process in the background was nonportable. Apparently the Windows equivalent is system(1,'some_cmd'), so that might be worth a try.

Replies are listed 'Best First'.
Re^2: explain my fork
by wirrwarr (Monk) on Jun 23, 2006 at 07:52 UTC
    An easy way to do what you want without using fork and exec is to do system('some_cmd &')
    Actually, this only works when you use a shell that understands the "&". That means, it doesn't work for most Windows users.


    daniel.