/* * Sample program for getppid system call - No.64 * * Name * getpid, getppid - get process identification * * Synopsis * #include * #include * * pid_t getpid(void) * pid_t getppid(void); * * Description * getpid returns the process ID of the current process. * (This is often used by routines that generate unique tem- * porary file names.) * * getppid returns the process ID of the parent of the cur- * rent process. */ #include #include #include main() { int pid; switch (pid = fork()) { case -1: perror("fork"); break; case 0: printf("in the child process\n"); printf(" current pid = %d\n", getpid()); printf(" parent pid = %d\n", getppid()); return 0; break; default: wait(NULL); printf("in the parent process\n"); printf(" current pid = %d\n", getpid()); break; } exit(0); }