简体   繁体   English

Bash 带有 kill 命令的脚本

[英]Bash script with kill command

If I try to kill a process in bash script it returns me the following error: : arguments must be process or job IDs如果我尝试终止 bash 脚本中的进程,它会返回以下错误::arguments must be process or job IDs

#!/bin/bash
PID=`cat /var/www/html/pid.txt`
kill -SIGKILL $PID

It acts like kill is getting a non-numerical value.它的行为就像kill正在获得一个非数值。 If the process ID just doesn't exist, you get a different error (no such process).如果进程 ID 不存在,则会出现不同的错误(没有这样的进程)。

I would look at the text file itself.我会看一下文本文件本身。 Make sure there aren't any special characters and that the PID is purely numerical.确保没有任何特殊字符并且 PID 是纯数字的。

Try something like this:尝试这样的事情:

kill -9 $(cat /var/www/html/pid.txt | sed -e 's/[^0-9]\+//g')

If the process just doesn't exist, I'd expect an error like this:如果该过程不存在,我预计会出现这样的错误:

bash: kill: (2100) - No such process

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM