Wednesday, February 19, 2014

Get my Process ID and Parent Process ID in C, by calling getpid() and getppid()

Example to Get my Process ID (PID) and Parent Process ID (PPID) by calling getpid() and getppid().

#include <stdio.h>
#include <sys/types.h>

main(){
 pid_t mypid;
 pid_t myppid;
 
 mypid = getpid();
 myppid = getppid();
 printf("My PID: %ld\n", (long)mypid);
 printf("My PPID: %ld\n", (long)myppid);
}

getpid() and getppid()