//===================================================== // Matt Kretchmar // A small program to create processes //===================================================== #include /* symbolic constants */ #include /* system data types */ #include /* Errors */ #include /* Input/Output */ #include /* Wait for Process Termination */ #include /* General Utilities */ int main ( int argc, char *argv[] ) { pid_t pid; /* variable to hold process id */ int i; int n = 0; if ( argc >= 2 ) n = atoi(argv[1]); for (i = 0; i < n; i++ ) { printf("Level %d\n",i); pid = fork(); if ( pid != 0 ) printf("%d child spawned\n",pid); sleep(1); } printf("Level %d\n",n); int status; while ( (pid = waitpid(-1,&status,0)) > 0 ) { printf("Parent (%d) waited for %d\n",getpid(),pid); } return 0; }