A Linux thread or forked process may change its name and/or its commandline as visible by ps
or in the /proc
filesystem.
When using the python-setproctitle
package, the same change occurs on /proc/pid/cmdline
, /proc/pid/comm
, the Name:
line of /proc/pid/status
and in the second field of /proc/pid/stat
, where only cmdline
is showing the full length and the other three locations are showing the first 15 chars of the changed name.
When watching multithreaded ruby
processes, it looks like the /proc/pid/cmdline
remains unchanged but the other three locations are showing a thread name, truncated to 15 chars.
man prctl
tells that /proc/pid/comm
is modified by the PR_SET_NAME
operation of the prctl
syscall but it does not say anything about /proc/pid/status
and /proc/pid/stat
.
man proc
says /proc/pid/comm
provides a superset of prctl PR_SET_NAME
which is not explained anymore.
And it tells that the second field of /proc/pid/stat
would still be available even if the process gets swapped out.
When watching JVM processes, all the mentioned locations give identical contents for all threads (the three places other than cmdline
all showing java
), but jcmd pid Thread.print
still shows different thread names for the existing threads, so it looks like Java threads are using some non-standard mechanism to change their name.
Is /proc/pid/comm
always identical to the Name:
line of /proc/pid/status
and the second field of /proc/pid/stat
or are there circumstances where one of these three places is offering different contents ?
Please provide an (easy to reproduce) example if differences are possible.