Summary
Using mirage
as an example, a python program that begins with a shebang:
#!/usr/bin/python
...
Looking at /proc/<pid>/comm
or using pgrep
, it appears like ...
... the process name is "mirage" when I call it via the shebang:
/usr/bin/mirage &
... but is "python" when I call python explicitly:
/usr/bin/python /usr/bin/mirage &
- I understand that a process can change its own name, but why isn't the name the same in both cases?
- Is there a generic way to know how a process was originally launched (using only
/proc
orgrep
information)?
Details - shebang
/home/martin> /usr/bin/mirage &
[1] 22638
/proc/<pid>/comm says it is "mirage"
/home/martin> cat /proc/22638/comm
mirage
pgrep finds it as "mirage" but not as "python"
/home/martin> pgrep -al mirage && echo "found" || echo "not found"
22638 /usr/bin/python /usr/bin/mirage
found
/home/martin> pgrep -al python && echo "found" || echo "not found"
not found
Details - python
/home/martin> /usr/bin/python /usr/bin/mirage &
[1] 21348
/proc/<pid>/comm says it is "python"
/home/martin> cat /proc/21348/comm
python
pgrep finds it as "python" but not as "mirage"
/home/martin> pgrep -al mirage && echo "found" || echo "not found"
not found
/home/martin> pgrep -al python && echo "found" || echo "not found"
21348 /usr/bin/python /usr/bin/mirage
found
pgrep -f '^(/usr/bin/python )?/usr/bin/mirage'
to have the same result for both cases (now there must be some clever regex to allow with or without path etc.) – A.B Aug 25 '18 at 18:43