当前位置:网站首页>使用 shell 脚本: 关闭特定进程
使用 shell 脚本: 关闭特定进程
2022-08-06 00:24:00 【Adunn】
使用 shell 脚本: 关闭特定进程
本文重点从以下几个方面进行过程说明:
- awk 说明
- grep -v grep 说明
- kill -9 说明
- xargs 说明
#!/bin/bash
NodeCount=`ps -ef |grep data_collector_client|wc -l`
echo "node count :" $NodeCount
if [ $NodeCount != "0" ];then
NodeCount=`expr $NodeCount - 1`
echo "will delete kill node : " $NodeCount
filelist=`ps -ef |grep data_collector_client|grep -v grep |awk '{print $2}'|tail -$NodeCount`
for file in $filelist
do
echo "will kill the node : " $file
# echo "will kill process id: " $( ps -ef |grep data_collector_client |awk '{print $2}')
#kill -9 $( ps -ef |grep data_collector_client |awk '{print $2}')
kill -9 $file
done
fi
awk ‘{print $2}’ :
表示 打印打印输出 ps 输出结果的第二列内容(即进程号),如下图所示(下图中为ie:428362):

grep -v grep
这里grep -v grep表示 过滤 grep 本身

kill -9 说明
在Linux系统下,我们进行程序调试或者是进行应用程序升级时,经常需要先对我们的目标程序进行kill关闭。此时最基础的办法就是先查找到目标进程的PID,然后再执行kill命令去关闭目标进程。
如:我们想要关闭掉svn相关的进程,首先执行ps -aux | grep
svn找到当前系统中有svnserve的进程,其PID为15889,接着直接执行kill -9 15889就可以关闭掉此svn的进程了。
xargs kill -9
ps -ef | grep procedure_name | grep -v grep | awk ‘{print $2}’ | xargs
kill -9上面指令中的procedure_name 即为所有关闭的进程名
边栏推荐
猜你喜欢
随机推荐
安全测试-数据安全测试(2)
技术术语积累
[TypeScript] What are literal types, type inference, type widening, and type narrowing?
OA项目线程内共享上下文实例(二)
How to fix wsa cannot be installed
2022-08-05 The sixth group Hide spring study notes
什么是中间人攻击?
Embedded system driver primary [7] - kernel memory management
[PMP Study Notes] Chapter 4 Project Integration Management
Chrome 谷歌浏览器,如何安装合适的浏览器驱动?
Teach you the object-src of the CSP series
2022中国大健康展,山东大健康展,济南健康展,健康产业展
OA项目CRUD和单元测试(一)
17、学习MySQL 事务
Day6:面试必考选择题
从零开始用C#做产品:私人日记(14)Sqlite封装
在VR里弹空气吉他?开发者:手势优化有技巧
手把手教你CSP系列之object-src
Go-Excelize API源码阅读(一)——NewFile()
央企施工企业数字化转型秘诀“一把手负责制”









