Javatpoint Logo
Javatpoint Logo

getpid() and getppid() function in C

In this article, we will discuss the getpid() and getppid() functions with their syntax and examples.


Getpid() and getppid() are two crucial procedures in the C programming language that let a process retrieve its own process ID (PID) and its parent process ID (PPID), respectively. These POSIX-compliant functions are frequently used in Unix-like operating systems. Gaining insight into the process management and hierarchy in a Unix system requires an understanding of these functions.

getpid() Method

The PID of the calling process is returned by the getpid() method, which is a distinctive identification given to each active process in the system. The getpid() function's syntax is as follows:


  1. The data types required by the function are included in the file sys/types.h.
  2. Access to numerous POSIX constants and types is available through h.

Example of getpid()

Let's take a look at a simple scenario to show how to use getpid() function:


Process ID: 1234


Every time you execute the program, the actual PID value (for example, 1234) will change because it depends on the system and the status of the running processes.

getppid() method

The PID of the calling process's parent process is returned by the getppid() method. The PID of the process that initiated the current process is thus retrieved. The getppid() function's syntax is as follows:


Example of getppid():

Let's take a look at a simple scenario to show how to use the getppid() function:


The output from the getppid() example will look somewhat like this:

Parent Process ID: 5678


The actual PPID value (for instance, 5678) will change depending on the system and the active parent process, much like with the getpid() function.


In conclusion, the C language's getpid() and getppid() functions are crucial for managing processes in Unix-like operating systems. They give developers access to details about a process's PID and PPID, enabling them to comprehend the process hierarchy and facilitate a variety of process-related tasks. Programmers can more efficiently control and manage processes within their programs by using these functionalities appropriately.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA