神刀安全网

Process Identification in Linux – Tutorial & Example

In this article we will discuss, how to differentiate and identify each process in linux.

Process ID

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,

pid_tgetpid() pid_tgetppid() 

File to be included for them is <unistd.h>

Let’s see an example,

#include <iostream> #include <unistd.h>   int main() {     pid_tprocessId = getpid();   pid_tparentProcessId = getppid();     std::cout<<"Process ID : "<<processId<<std::endl;   std::cout<<"Parent Process ID : "<<parentProcessId<<std::endl;      return 0; } 

Output

Process ID : 3825

Parent Process ID : 3560

To check the process id and parent process id of all running process, use following command,

ps -fe 

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.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Process Identification in Linux – Tutorial & Example

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址