I learned recently of pidof
, and I was comparing it to pgrep
. While doing that, I noticed that pidof
returned several PIDs for Firefox, while pgrep
returned just one.
I checked pgrep
's man page and experimented with its toggles, and got the expected output with -f
:
-f, --full
The pattern is normally only matched against the process name.
When -f is set, the full command line is used.
Now, I knew of ps
making distinctions between the full path to a command, 'simple' command name (like basename
on the fullpath) and the full args
, but I had never heard of process names.
In the case below, all the other processes are children of 4661
, so I'm guessing Firefox forked them to take advantage of multiprocessing.
The questions, then:
- What are process names?
- How and why do processes set them?
Looking at these posts, it seems that it may or may not be done by changing argv[0]
or calling prctl(PR_SET_NAME)
, and that it is used simply to help on debugging, identifying which subprocess is doing what (or, sometimes, to fool the user thinking a process is something else).
Is that so? Or are process names something in addition to argv
?
$ pidof firefox
5495 5463 5391 5384 5380 5351 5330 5311 5239 5184 4661
$ pgrep firefox
4661
$ pgrep -f firefox
4661
5184
5239
5311
5330
5351
5380
5384
5391
5463
5495
$ pgrep -fl firefox
4661 firefox
5184 Web Content
5239 Web Content
5311 Web Content
5330 Web Content
5351 Web Content
5380 Web Content
5384 Web Content
5391 Web Content
5463 Privileged Cont
5495 WebExtensions
$
man ps