previous | start | next

Tracing Execution for calls to fork()

Horizontal lines represent the execution of one process.

Vertical inserted to indicate 'forking' a new process.

Example:

(In this example P represents the printf statement.)

   19   int main(int argc, char* argv[])
   20   {
   21     int pid;
   22   
   23     pid = fork();
   24     printf("pid = %d\n", pid);
   25   
   26     return 0;
   27   }


Trace Graph:

 -23---+--24--P---
       |
       +--24--P---

Output:
  pid = 0
  pid = ... (a value > 0)

OR

 pid = ... (a value > 0)
 pid = 0

Same graph, but abreviated to omit the line numbers:

 ---+--P---
    |
    +--P---



previous | start | next