/* lab 3 D : o means orphan and z means zombie */ #include #include int main(int argc, char *argv[]) { int pid; pid = fork(); if (pid < 0) { /* an error occurred */ printf("Fork Failed\n"); exit(1); } else if (pid == 0) { /* child process */ if (argv[1][0] == 'o') sleep(30); /* child still executing when parent terminates */ printf("Child completed\n"); exit(0); } else { /* parent process */ /* parent does not wait for child */ if (argv[1][0] == 'z') sleep(30); /* child completes before parent */ printf("Parent completed\n"); exit(0); } }