Home » C programs » Advance C 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;
}
Process ID: 1298
Parent Process ID: 879





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.