<分区>
我试过这段代码,但它不起作用
#!/bin/sh
#Find the Process ID for syncapp running instance
PID=`ps -ef | grep syncapp 'awk {print $2}'`
if [[ -z "$PID" ]] then
Kill -9 PID
fi
它在 awk 附近显示错误。
请提出任何建议。
<分区>
我试过这段代码,但它不起作用
#!/bin/sh
#Find the Process ID for syncapp running instance
PID=`ps -ef | grep syncapp 'awk {print $2}'`
if [[ -z "$PID" ]] then
Kill -9 PID
fi
它在 awk 附近显示错误。
请提出任何建议。
最佳答案
实际上,最简单的方法是像下面这样传递 kill 参数:
ps -ef | grep your_process_name | grep -v grep | awk '{print $2}' | xargs kill
关于bash - 用于捕获进程 ID 并在存在时将其杀死的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13910087/