简体   繁体   中英

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

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

It acts like kill is getting a non-numerical value. If the process ID just doesn't exist, you get a different error (no such process).

I would look at the text file itself. Make sure there aren't any special characters and that the PID is purely numerical.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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