// file: test.c // Comp.Sys.Org.II, Spring 2005, Yap. // The following code is a simple modification of the "fork.c" code from // // Dr Ian G Graham, Department of Information Technology, GUGC // Copyright © 2000-2003 // #include #include #include #include #include #include extern int errno; /* system error number */ void syserr(char* ); /* error report, abort routine */ int main(int argc, char *argv[]) { pid_t pid; int rc; pid = getpid(); printf("Process ID before fork: %d\n", pid); switch (fork()) { case -1: syserr("fork"); case 0: /* execution in child process */ pid = getpid(); printf("Process ID in child after fork: %d\n", pid); execlp("echo", "0", "Child to world: Hello!",NULL); syserr("execl"); } /* continued execution in parent process */ pid = getpid(); printf("Process ID in parent after fork: %d\n", pid); //getchar(); // supposed to hang until I type something exit(0); } void syserr(char * msg) { fprintf(stderr,"%s: %s", strerror(errno), msg); //abort(errno); // variant abort(); }