Q:

C program to get Process Id and Parent Process Id in Linux

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C language important programs ( Advance Programs )

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to find the size of a file in Linux... >>
<< fork() function explanation and examples in Linux ...