spawn a process?

I need to write a CGI program that
can spawn a sub process. The sub
process is very time consuming. So I
want the CGI program to send browser a sub process id number and quit HTTP connection before the sub process finished.  

Later, user can check the status of the sub process by its id number.  This is under Unix. Is there some sample codes doing this?
Who is Participating?
jhurstConnect With a Mentor Commented:
fork() is the function that you need.  It creates a second copy of the process.  This second copy can do the work you want and the fork() returns the process id of the forked process.  The forked process knows that it is the forked one since its pid is the pid.  This process can then do whatever needs to be done while the original one send the required information to the user.

The one thing to be aware of is that many web masters restrict forked processes in the cpu cycles that they can use.

system("/programdir/bin/program &");

The & tells the starter that it can go on without it (dont wait).

I don't know how to get a system PID, sorry.
All Courses

From novice to tech pro — start learning today.