Process Identification in Linux – Tutorial & Example
In this article we will discuss, how to differentiate and identify each process in linux.
Each process in Linux has a unique id and has a parent. We can get the process id of a running process and its parent’s process id using following functions,
File to be included for them is <unistd.h>
Let’s see an example,
pid_t processId = getpid();
pid_t parentProcessId = getppid();
std::cout<<"Process ID : "<<processId<<std::endl;
std::cout<<"Parent Process ID : "<<parentProcessId<<std::endl;
Process ID : 3825
Parent Process ID : 3560
To check the process id and parent process id of all running process, use following command,
Output will contains many rows with following columns i.e
UID PID PPID C STIME TTY TIME CMD
varun 3223 1880 0 23:10 ? 00:00:02 /usr/lib/chromium-browser/chro
varun 3250 1880 0 23:10 ? 00:00:01 /usr/lib/chromium-browser/chro
Here PID represents process id and PPID represents Parent Process Id
What is an Orphan Process
Every process has a parent process.
If a parent process terminates then all its children process become orphan processes. As soon as a process becomes orphan, the init process becomes their parent.
Process ID of init process is 1.Follow @thisPtr