Thu
15
Oct '09
|
|
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.
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.
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.