Currently my machine has 5 processes running scripts through python
, but Linux thinks only 2 of them have the name python
(according to /proc/$pid/stat). That is, pgrep -af python
shows:
1784 /usr/bin/python -Es /usr/sbin/foo
2306 /usr/bin/python /usr/bin/bar
16964 /usr/bin/python /usr/bin/terminator --geometry=1400x1000
24137 python /home/me/bin/baz.py --arg 70000
25760 python2 -m guake.main
whereas pgrep -a python
shows only:
24137 python /home/me/bin/baz.py --arg 70000
25760 python2 -m guake.main
Here are the names that Linux has given to these processes:
% for pid in $(pgrep -f python); do cut -d' ' -f2 /proc/$pid/stat; done
(foo)
(bar)
(/usr/bin/termin)
(python)
(python2)
So how does Linux decide whether python
or the script name will be the process name? And why do foo
and bar
become the name when the terminator
process gets the full path instead?
I assume the manner of invocation matters. I don't know how these three programs were invoked, but here are their shebangs:
/usr/sbin/foo: #!/usr/bin/python -Es
/usr/bin/bar: #!/usr/bin/python
/usr/bin/terminator: #!/usr/bin/python
This one was definitely invoked using the shebang:
/home/me/bin/baz.py: #!/usr/bin/env python
And Guake is launched from a Bash script like so:
exec /usr/bin/env python2 -m guake.main "$@" </dev/null >/dev/null 2>&1 &
My naive guess is that /usr/bin/env
causes the word following it to become the process name, but I assume there's more to it than just that. (And even if that is the case, how does it assign that name?)