Thu
15
Oct '09
pgrep or pkill sometimes do not find process
by Frank Spychalski filed under Computer, Work

The usual problem: you want to kill a process.

$ ps aux | grep randomprocessname
psycho 20429 0.0 0.0 11824 1580 pts/7 S+ 12:00 0:00 /bin/bash ./randomprocessname
psycho 20528 0.0 0.0 4188 740 pts/17 R+ 12:00 0:00 grep randomprocessname
$ pkill -9 randomprocessname
WTF? Kill that sucker!
$ pkill -9 randomprocessname
No typo... Am I crazy?
$ pgrep randomprocessname
What's wrong?
$ pgrep randomprocessna
20429
$ pkill -9 randomprocessna

For some arcane reason pgrep/pkill matches only the first 15 characters.


2 Responses to “pgrep or pkill sometimes do not find process”

  1. 1

    I think only the first 15 characters are saved in kernel space as the process name. For longer comparisons the argv needs to be read and that can be swapped out.

    man pkill:

    NOTES: The process name used for matching is limited to the 15 characters present in the output of /proc/pid/stat. Use the -f option to match against the complete command line, /proc/pid/cmdline.

    Mike (October 15th, 2009 at 12:16)
  2. 2

    Yes, it makes sense. But I was confused because I used a script which worked fine for $binary_name but failed when I used it for a binary with the -canary suffix.

    Frank Spychalski (October 15th, 2009 at 12:52)

Any comments? Or questions? Just leave a Reply: