#include /* Primitive System Data Types */ #include /* Input/Output */ #include /* Symbolic Constants */ #include /* General Utilities */ /* loads the environment variables (i.e. PATH) */ extern char **environ; /* forks 10 new processes, each of which uses execve() to run ps */ int main() { pid_t pid; /* variable to store the child's pid */ int i; for (i = 0; i < 10; i++) { pid = fork(); /* create a child process */ /* if the fork() failed, exit with -1 */ if (pid < 0) { fprintf(stderr, "Fork Failed"); exit(-1); } /* else if this is the child thread, execve(ps) */ else if (pid == 0) { execve("/bin/ps", NULL, NULL); } /* if this is the parent thread, wait until * the child returns then go fork another process */ else { wait(NULL); printf("Child Complete\n"); } } exit(0); }