lotus

贵有恒何必三更眠五更起 最无益只怕一日曝十日寒

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  1846 随笔 :: 0 文章 :: 109 评论 :: 288万 阅读

 

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 
posted on   白露~  阅读(4812)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示