getppid() and getpid() in Linux Last Updated : 26 Sep, 2017 Summarize Comments Improve Suggest changes Share Like Article Like Report Both getppid() and getpid() are inbuilt functions defined in unistd.h library. getppid() : returns the process ID of the parent of the calling process. If the calling process was created by the fork() function and the parent process still exists at the time of the getppid function call, this function returns the process ID of the parent process. Otherwise, this function returns a value of 1 which is the process id for init process. Syntax: pid_t getppid(void); Return type: getppid() returns the process ID of the parent of the current process. It never throws any error therefore is always successful. CPP // C++ Code to demonstrate getppid() #include <iostream> #include <unistd.h> using namespace std; // Driver Code int main() { int pid; pid = fork(); if (pid == 0) { cout << "\nParent Process id : " << getpid() << endl; cout << "\nChild Process with parent id : " << getppid() << endl; } return 0; } Output(Will be different on different systems): Parent Process id of current process : 3849 Child Process with parent id : 3851 NOTE: At some instance of time, it is not necessary that child process will execute first or parent process will be first allotted CPU, any process may get CPU assigned, at some quantum time. Moreover process id may differ during different executions. getpid() : returns the process ID of the calling process. This is often used by routines that generate unique temporary filenames. Syntax: pid_t getpid(void); Return type: getpid() returns the process ID of the current process. It never throws any error therefore is always successful. CPP // C++ Code to demonstrate getpid() #include <iostream> #include <unistd.h> using namespace std; // Driver Code int main() { int pid = fork(); if (pid == 0) cout << "\nCurrent process id of Process : " << getpid() << endl; return 0; } Output (Will be different on different systems): Current process id of Process : 4195 Comment More infoAdvertise with us Next Article hostid command in Linux with examples P Pushpanjali chauhan Improve Article Tags : Linux-Unix system-programming CPP-Library Similar Reads id command in Linux with examples The 'id' command in Linux is a powerful tool used to display user and group names along with their numeric IDs (User ID - UID or Group ID - GID) of the current user or any specified user on the system. This command is particularly useful for system administrators and users who need to verify user id 3 min read hostid command in Linux with examples hostid is a command in Linux that is used to display the Host's ID in hexadecimal format. It provides a quick and straightforward way to retrieve the host ID, allowing administrators to associate it with software licenses or perform system-specific operations. Syntax of `hostid` command in Linuxhost 1 min read getent command in Linux with examples The 'getent' command in Linux is a powerful tool that allows users to access entries from various important text files or databases managed by the Name Service Switch (NSS) library. This command is widely used for retrieving user and group information, among other data, stored in databases such as ' 5 min read Linux system call in Detail A system call is a procedure that provides the interface between a process and the operating system. It is the way by which a computer program requests a service from the kernel of the operating system. Different operating systems execute different system calls. In Linux, making a system call involv 4 min read Get Username by User ID in Linux The need to get user names by User ID is frequently encountered by system administrators in the Linux world. This task is necessary to manage permissions, diagnose, or simply identify users of the Linux system for different management purposes. Fortunately, Linux provides several methods to achieve 3 min read Real, Effective and Saved UserID in Linux Every user in Unix like operating system is identified by a different integer number, this unique number is called as UserID. There are three types of UID defined for a process, which can be dynamically changed as per the privilege of task. The three different types of UIDs defined are : 1. Real Use 3 min read Like