bash - 用于捕获进程 ID 并在存在时将其杀死的 Shell 脚本

标签 bash shell scripting

<分区>

我试过这段代码,但它不起作用

#!/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/

相关文章:

git - 在 git 的命令行中显示 merge 状态的方法

linux - shell脚本的开关

linux - 如何读取每行命令 lspci 的结果作为数组的一个元素?

c++ - 如何使用 Lua C API 获取 .lua 脚本中所有表名的列表?

javascript - jQuery 对话框中的箭头

storage - "best"存放脚本的方式是什么?

Bash:将命令替换的输出分配给整数变量

linux - Bash 脚本 - 斐波那契

regex - 如何删除除一个扩展名之外的所有文件

linux - Unix,如何将 crontab 放入 shell 脚本中