#include /* has the definition of pid_t */ #include /* The header defines miscellaneous symbolic constants and types, and declares miscellaneous functions. Like fork()*/ #include #include int randomNumber; int main () { int i; pid_t parent_id=getpid (), child_pid; /* initialize random seed: */ srand(time(NULL)); randomNumber = rand()%1000; printf ("The main program process ID is %d\n", (int)parent_id); /*The fork() function creates a new process. The new process (child process) is an exact copy of the calling process (parent process).*/ for (i = 0; i< 10 && getpid () == parent_id;i++) child_pid = fork (); if (child_pid != 0) { printf ("This is the parent process, with id %d ", (int) getpid ()); printf ("and my child’s process ID is %d\n", (int) child_pid); }else{ printf ("This is the child process, with id %d and RANDOM %d\n", (int) getpid (), ++randomNumber); } return 0; }