linux根據進程名終止進程


 

linux根據進程名終止進程

實驗環境

操作系統:CentOS Linux release 7.3.1611 (Core) IP: 192.168.230.134
  • 1
  • 2
  • 3

查看進程情況

使用ps命令直接查看所有進程:

[root@localhost ~]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 128088 6748 ? Ss Sep22 0:26 /usr/lib/systemd/systemd --switched-root --system --deserialize 2 root 2 0.0 0.0 0 0 ? S Sep22 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Sep22 0:06 [ksoftirqd/0] root 7 0.0 0.0 0 0 ? S Sep22 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S Sep22 0:00 [rcu_bh] 等
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

查看指定進程情況

使用管道函數篩選出指定進程,示例中使用mongo作為查詢條件

[root@localhost ~]# ps aux|grep 'mongo' mongod 28492 0.4 6.8 1218208 275100 ? Sl Sep24 11:13 /usr/bin/mongod -f /etc/mongod.conf root 59135 0.0 0.0 112644 968 pts/1 R+ 19:11 0:00 grep --color=auto mongo
  • 1
  • 2
  • 3

篩選出pid號

使用awk命令篩選出pid用作刪除

[root@localhost ~]# ps aux|grep 'mongo'|awk '{print $2}' 28492 59137
  • 1
  • 2
  • 3

強制終止進程

使用kill命令強制重啟進程

[root@localhost ~]# ps -ef|grep mongo|grep -v grep|awk '{print $2}'|xargs kill -9 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM