contents   index   previous   next



Unix.fork()

syntax:

Unix.fork()

return:

number - 0 or a child process id. 0 is returned to the child process, the id of the child process is returned to the parent.

 

description:

A call to this function creates two duplicate processes. The processes are exact copies of the currently running process, so both pick up execution from the next statement. Because these processes are duplicates, they share identical all resources the original one had at the time of fork()ing, but not any allocated later. For instance, any open file handles or sockets are shared. If both processes write to them, the output will be intermixed since each write from either process advances the file pointer for both. Unix.wait() allows you to wait for completion of a Child. Using Unix.wait() or Unix.waitpid() is important to prevent annoying zombie processes from building up.

 

see:

Unix.kill(), Unix.wait(), Unix.waitpid()

 

example:

// Here is a simple example:

 

function main()

{

   var id = Unix.fork();

 

   if( id==0 )

   {

      Clib.printf("Child here!\n");

      Clib.exit(0);

   }

   else

   {

      Clib.printf("started child process %d\n", id);

   }

}

 


Unix.kill()