pgrep 查询进程的工具

时间:2023-03-09 04:23:39
pgrep 查询进程的工具

pgrep

1:简介

  pgrep 是通过程序的名字来查询进程的工具,一般是用来判断程序是否正在运行。在服务器的配置和管理中,这个工具常被应用,简单明了;

1:用法

#pgrep 参数选项 程序名
  常用参数
  -l 列出程序名和进程ID;
  -o 进程起始的ID;
  -n 进程终止的ID;
  举例:
  

[root@localhost ~]# pgrep -lo httpd
   httpd
  [root@localhost ~]# pgrep -ln httpd
   httpd
  [root@localhost ~]# pgrep -l httpd
   httpd
   httpd
   httpd
   httpd
   httpd
   httpd
   httpd
   httpd
  [root@localhost ~]# pgrep httpd
  
  
  
  
  
  
  
  
root@VM_160_34_centos:~/shell> AAA="'pgrep httpd'"
root@VM_160_34_centos:~/shell> echo AAA
AAA
root@VM_160_34_centos:~/shell> echo $AAA
'pgrep httpd'
root@VM_160_34_centos:~/shell> AAA="`pgrep httpd`"
root@VM_160_34_centos:~/shell> echo $AAA root@VM_160_34_centos:~/shell> pgrep httpd
root@VM_160_34_centos:~/shell> echo $? root@VM_160_34_centos:~/shell> pgrep nginx root@VM_160_34_centos:~/shell> AAA="`pgrep nginx`"
root@VM_160_34_centos:~/shell> echo $? root@VM_160_34_centos:~/shell> echo $AAA root@VM_160_34_centos:~/shell>