C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting
C > Gnu-Linux sample source codes
Get parent pid
Get parent pid #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(void) { pid_t pid; pid = fork(); if(pid == 0) { printf("I am child with pid: %d\n", getpid()); printf("as a child my parent pid is: %d\n", getppid()); } else { printf("I am a parent with pid: %d\n", getpid()); printf("as a parent my child pid is: %d\n", pid); } /* Following code executes in both processes */ printf("oew.. I have to exit: %d\n", getpid()); exit(0); }
Privacy Policy
|
Link to Us
|
Links