Home »
C programs »
C advance programs
C program to get Process Id and Parent Process Id in Linux
This program will get the Process Id and Parent Process Id of the current Process in C programming Linux.
Here we are using two functions getpid() to get Process Id and getppid() to get Parent Process Id of the current process. These functions are declared in <unistd.h> header file.
Process Id and Process Parent Id using C program
/*C program to get Process Id and Parent Process Id in Linux.*/
#include <stdio.h>
#include <unistd.h>
int main()
{
int p_id, p_pid;
p_id = getpid(); /*process id*/
p_pid = getpid(); /*parent process id*/
printf("Process ID: %d\n", p_id);
printf("Parent Process ID: %d\n", p_pid);
return 0;
}
Output
Process ID: 1298
Parent Process ID: 879
C Advance Programs »