Score:1

pkill doesn't kill

tm flag

I tried to kill a process using pkill -9 <pid>

Whenever I run that command it returns nothing and the process isn't killed either.

How do I proceed now?

Edit:

I was stupid trying to use pkill with pid. pkill takes the name of the process not pid. kill is the command that takes pid as pointed out in the accepted answer.

However the other answer actual does a good job explaining the actual possibility of pkill not killing and is very well written.

pierrely avatar
cn flag
alternative killall -9 <name> and maybe run as sudo. you can also get "$(pidof <name>)" when you need a number, and you might get several (like Firefox and it's download manager window, then you need to pass through the array from that pidof
Score:6
bd flag

If I remember correctly (I never use it) pkill uses the process name, not the PID. to use the PID use kill instead of pkill.

user10489 avatar
in flag
Good point. A process won't die if you miss when you try to kill it. pkill typically only searches the command name. pkill -a or -f searches the command arguments too, but this is dangerous and might kill too much. I suggest using pgrep before pkill to see if you are actually matching anything.
Score:4
in flag

There are exactly three reasons why kill -9 will not kill a process. (Old man pages labeled this as "Kill with extreme prejudice". A process can not avoid -9, but only delay its death.)

You can check on the process with ps -O stat -p 1234 for example. Examine the status (S) column:

The three reasons why a process does not immediately die from -9 are:

  • It's already dead -- it's a zombie. (status=Z) It will go away when its parent waits for it (and collects the zombie) or the parent process itself dies.
  • It's stuck in a device wait. (status=D) The only way to kill these is to get the device to release it or reboot. This may require waiting, or physically manipulating the device, or some other out of band way to "kick" the stuck device. (And in rare cases, a reboot will fail and hang, and you'll have to power cycle.)
  • It's suspended (status=T), in which case kill -9 does kill it, but it doesn't actually die until the process is resumed (kill -CONT)

The kill command does actually return something, although if it succeeds, doesn't print anything. All commands have a return value. You can check it with echo $? immediately after running the command. If the return value is 0, the kill succeeded and nothing prints. Any other value is an error, and it should print the error; possible errors might be Permission denied (or operation not permitted), and No such process. pkill has a few errors that are slightly more interesting.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.