Linux shell: How to read a command argument from a file?

I have a process id in the "pid" file. I would like to kill it.

Something like:

kill -9 <read pid from file> 

I tried:

 kill -9 `more pid` 

but that will not work. I also tried xargs , but can't wrap myself around it.

+7
linux pipe xargs
source share
5 answers

Let me summarize all the answers.

 kill -9 $(cat pid) kill -9 `cat pid` cat pid | xargs kill -9 
+12
source share

Whether there is a

 kill -9 $(cat pid) 

works for you?

+13
source share

My preference

 kill -9 `cat pid` 

which will work for any team in backticks.

+3
source share

kill -9 $(cat pid) or cat pid | xargs kill -9 cat pid | xargs kill -9 will work

+2
source share

You must start gradually, and then move on to the difficult thing to kill the process if it does not want to play beautifully.

The SIGKILL (-9) signal cannot be detected, and this will mean that any resources held by the process will not be cleared.

First try using SIGTERM (-15), and then check for the existence of the process by running kill -0 $ (cat pid). If he still hangs around, then, by all means, knocks him down with -9.

SIGTERM can be captured by a process, and any process that has been correctly written must have a signal handler to catch SIGTERM and then clear its resources before exiting.

+2
source share

All Articles