==========================================================
pidof and pgrep examples and turorails:
==========================================================
---------------------------------------------------------------------------------------
===>> pidof : Find the process ID of a running program
---------------------------------------------------------------------------------------
-s : Single shot- this instruct the program to only return one pid.
It will return only One pid
-o : Tell pidof to omit processes with that process id.
It Ommit the pid.
Example :
#pidof -o 1123 mingetty (If there are 4 process of mintetty, So the cmd will ommit the pid provided)
for example: it is used when you do not want to kill specific pid's
ex: #pidof -o 1123 12345 mingetty
-----------------------------------------------------------------------------------------------
===>> pgrep: look up or singnal processess based on name and other attributes.
----------------------------------------------------------------------------------------------
Both commands(pidof and pgrep) will show the process id for the command mingetty
ex:
#pidof mingetty
or
#pgrep mingetty
pidof <command>
or
pgrep <command>
1) #pgrep -u root sshd
will only list the process called sshd AND OWNED By root.
2) #pgrep -u root,bob
will list the processes owned by root or bob users.
3) #pgrep -d " " -u root
-d delimiter: list all the process after space..
4) #pgrep -l -u root
-l : List the process name as wll as there PIDS
5) #pgrep -n <cmd>
print the latest pid for the process(cmd),
-n Select only the newet (most recent started) for matching process.
6) #pgrep -o <cmd>
-o Select only the oldest (least recent started) for matching process.
=> Assuming that the process Id 7 is for kthread cmd(It is system cmd)
#pgrep -l kthread
7) #pgrep -P 7 -l (It will list all the child processess for the Main process(kthread)) and list the cmd as well as its pid
-P : Only match process whose parent process ID is listed:
8) #pgrep -u root -v -l (Will not list the processes by user root)
List all the running process and it name owned by all users except root
-v negate
==========================================================
pidof and pgrep examples and turorails
精选 转载上一篇:Reading vmstat in linux – Part 1
下一篇:Bg, Fg, &, Ctrl-Z – 5 Examples to Manage Unix Background Jobs
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
pidof 的用法
PIDOF(8) Linux System Administrator’s Manual
函数 职场 休闲 pidof -
pgrep
优势:可以只显示进程号 pgrep -l
linux 进程名 IT