man pgrep
says the following about -f
option:
-f The pattern is normally only matched against the process name.
When -f is set, the full command line is used.
What does it mean to say the full command line is used?
commandcommand linegrepprocess
man pgrep
says the following about -f
option:
-f The pattern is normally only matched against the process name.
When -f is set, the full command line is used.
What does it mean to say the full command line is used?
Best Answer
It means that without
-f
,pgrep
only searches for the provided regexp in the command names, while with-f
it searches it in their arguments (where the first argument (argv[0]
) is not necessarily the same as the command name).And if we cause
argv[0]
to be different from the command name (on Linux as seen in/proc/$pid/stat
) as when usingzsh
'sARGV0
:There's a lot of potential confusion regarding process name on Unix and Linux. There are 3 attributes of a process that could claim being the process name:
ps
or found in/proc/$pid/stat
. However, it should be noted that on Linux, it can be changed usingprctl(PR_SET_NAME...)
.mmap
ed for execution in the process and preferably the path as it was invoked (for scripts, that would be the path provided in the shebang line for instance). On Linux, you can get it with areadlink
or/proc/$pid/exe
. That one, you can't change without calling anotherexecve
(though you could in theory load a new executable in memory and execute its code without callingexecve
, see for instance some attempts at a user land execve)./proc/$pid/cmdline
, but a process can also change it by modifying the memory pointed to byargv[0]
.It should also be noted that there's a lot of variation among the difference Unices.