how to read a PID from a text file and kill the corresponding process
I've got a command in a shell script:
Code:
php ./script.php > output.txt & echo $! > script.pid I'd like to make another shell script which will read the pid from script.pid and kill that process. I tried this but it didn't work: Code:
Mac:server sneakyimp$ sudo kill -9 < cat script.pid |
Code:
pid=$(cat script.pid);kill -9 $pid Code:
kill -9 $(cat script.pid) |
It is a bad idea to use kill -9 to terminate a process in a regular fashion. When a process receives a kill signal (SIGKILL) it cannot do any cleanup actions like freeing rescources. Running this on a server where many of these processes will be initiated and terminated and the server will not be reset for a long time, this will lead to consuming all available memory.
Only in situations where you want to terminate a process no matter what you may use kill -9. All other applications should use kill -15, SIGTERM which terminates a process in a clean and orderly way. jlinkels |
Excellent, guys. Thank you both.
|
All times are GMT -5. The time now is 05:11 AM. |