Unknown whether this bug is long-term (since 2.6.9, which is when I think this functionality was introduced) or if it is relatively recent. When setting a process name using prctl(PR_SET_NAME, ...), only the first fifteen characters of the supplied process name are retrievable. It will set the full process name, so prctl(PR_SET_NAME, "VeryLongProcessName", NULL, NULL, NULL) will set it, and "killall VeryLongProcessName" will work from the terminal, but /proc/<pid>/status (and prctl(PR_GET_NAME, pointer, NULL, NULL, NULL), too) will only return the first 15 characters of the process name that was set. Am attaching a small C program to demonstrate this. Example output of the program: Wednesday, 2008-Oct-15 at 01:26:30 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[1-103/5664-0]:test> ./prctl ShortName Current process name: prctl Setting process name: ShortName New process name: ShortName Wednesday, 2008-Oct-15 at 01:28:25 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[1-104/5665-0]:test> ./prctl VeryLongProcessName Current process name: prctl Setting process name: VeryLongProcessName New process name: VeryLongProcess
Created attachment 18317 [details] Program demonstrating the bug This program demonstrates the bug reported. Compile: gcc -Wall -W -ggdb -o prctl prctl.c Execute: ./prctl <name_to_test>
No, PR_SET_NAME will use only 15 bytes and save it in current->comm which is 16 bytes long.
Yes, but it is still saving it somewhere and just not displaying it. If I add a call to sleep() and put it in the background after setting its name, I wind up with it being killall'able only by the name it was set by. So it's just not displaying it. Further proof, killing with the short name returned by the kernel fails: Wednesday, 2008-Oct-15 at 03:44:56 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[0-15/5761-0]:test> ./prctl VeryLongProcessName & sleep 1 [1] 5052 Current process name: prctl Setting process name: VeryLongProcessName New process name: VeryLongProcess PR_SET_NAME value: 15 PR_GET_NAME value: 16 Try to kill me with killall... Wednesday, 2008-Oct-15 at 03:45:02 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[1-16/5762-0]:test> killall VeryLongProcess VeryLongProcess: no process killed Wednesday, 2008-Oct-15 at 03:45:07 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[1-17/5763-1]:test> killall VeryLongProcessName [1] + terminated ./prctl VeryLongProcessName
Created attachment 18318 [details] Demo, with added sleep(). See last comment re: how the VeryLongProcessName is stored, but not returned; the process only dies when killall'ed with its VeryLongProcessName that was set (Either the kernel should limit it hard to 15 characters, which while annoying, would be consistent, or it should allow a more reasonable size for process names---there are cases where setting a long one would be very desirable).
prctl sets the in kernel notion of the name, killall I believe grovels around in the process own memory space for argv[0]. Anyway this is not a bug and will not be changing
Created attachment 18325 [details] Demo, with ability to prompt instead of supply process name. Example usage (proves comment 5 wrong): Wednesday, 2008-Oct-15 at 12:17:55 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[3-187/5811-0]:test> ./prctl Enter process name to set: foobar Current process name: prctl Setting process name: foobar New process name: foobar PR_SET_NAME value: 15 PR_GET_NAME value: 16 Try to kill me with killall... ^Z zsh: suspended ./prctl bg Wednesday, 2008-Oct-15 at 12:18:05 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[4-188/5812-20]:test> bg [4] - continued ./prctl Wednesday, 2008-Oct-15 at 12:18:05 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[4-189/5813-0]:test> ps PID TTY TIME CMD 3360 pts/0 00:00:00 spket 3361 pts/0 00:06:44 java 12528 pts/0 00:00:05 emacs 12721 pts/0 00:00:00 test 12874 pts/0 00:00:00 foobar 12893 pts/0 00:00:00 ps 29885 pts/0 00:00:04 zsh Wednesday, 2008-Oct-15 at 12:18:07 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[4-190/5814-0]:test> cat /proc/12874/cmdline|xxd 0000000: 2e2f 7072 6374 6c00 ./prctl. Wednesday, 2008-Oct-15 at 12:18:17 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[4-191/5815-0]:test> killall prctl prctl: no process killed Wednesday, 2008-Oct-15 at 12:18:22 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[4-192/5816-1]:test> killall foobar [4] - terminated ./prctl
Now, as demonstrated in the last comment, killall does not use argv[0] because argv[0] remains ./prctl. However, the process is no longer killable using "killall prctl", either. It is only killable using the name set by prctl(). It is still killall'able, however, using a VeryLongProcessName: Wednesday, 2008-Oct-15 at 12:21:05 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[3-203/5827-0]:test> ./prctl Enter process name to set: VeryLongProcessName Current process name: prctl Setting process name: VeryLongProcessName New process name: VeryLongProcess PR_SET_NAME value: 15 PR_GET_NAME value: 16 Try to kill me with killall... ^Z zsh: suspended ./prctl bg Wednesday, 2008-Oct-15 at 12:21:40 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[4-204/5828-20]:test> bg [4] - continued ./prctl Wednesday, 2008-Oct-15 at 12:21:40 - mbt@zest - Linux v2.6.27 Ubuntu Intrepid:[4-205/5829-0]:test> killall VeryLongProcessName [4] - terminated ./prctl VeryLongProcessName is *definitely* not in the argument list in this run. That having been said, is there a reason to have the name stored (or, I suppose, just retrievable) limited to 15 characters? It would seem that an image being executed with a long name is also limited to 15 characters in its display name via /proc and friends, but is killall'able using its full name. (unless of course it sets a new name, and then it's not killall'able using its full name, but only the name that it sets).