7

I have process id in a file "pid" I'd like to kill it.

Something like:

kill -9 <read pid from file>

I tried:

kill -9 `more pid` 

but it does not work. I also tried xargs but can't get my head around it.

John Rudy
  • 37,282
  • 14
  • 64
  • 100
Igor Katkov
  • 6,290
  • 1
  • 16
  • 17

5 Answers5

13

Does

kill -9 $(cat pid)

work for you?

sdtom
  • 890
  • 4
  • 8
12

Let me summarize all answers

kill -9 $(cat pid)
kill -9 `cat pid`
cat pid | xargs kill -9
Igor Katkov
  • 6,290
  • 1
  • 16
  • 17
3

my preference is

kill -9 `cat pid`

that will work for any command in the backticks.

BCS
  • 75,627
  • 68
  • 187
  • 294
2

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

Chris AtLee
  • 7,798
  • 3
  • 28
  • 27
2

You should be starting off gradually and then move up to the heavy stuff to kill the process if it doesn't want to play nicely.

A SIGKILL (-9) signal can't be caught and that will mean that any resources being held by the process won't be cleaned up.

Try using a kill SIGTERM (-15) first and then check for the presence of the process still by doing a kill -0 $(cat pid). If it is still hanging around, then by all means clobber it with -9.

SIGTERM can be caught by a process and any process that has been properly written should have a signal handler to catch the SIGTERM and then clean up its resources before exiting.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Rob Wells
  • 36,220
  • 13
  • 81
  • 146