#include #include #include #include #include main() { int pid, status, i; char *newargv[4]; newargv[0] = "cal"; newargv[1] = "9"; newargv[2] = "2020"; newargv[3] = NULL; pid = fork(); if (pid == 0) { /* for (i = 0; i < 1000000000; ++i) ; printf ("I'm in the child. My process number is %d.\n", getpid()); printf ("%d\n", *((int *) 0)); */ status = execv("/usr/bin/cal", newargv); //status = execv("aaaa", newargv); printf("execv returned %d\n", status); } else { wait(& status); printf ("I'm in the parent. My process number is %d.\n", getpid()); // Look at section 2 man page for wait for details: man -s 2 wait if (WIFEXITED(status)) printf("Child terminated normally.\n"); else if(WIFSIGNALED(status)) printf("Child was terminated by a signal.\n"); } }