When I use either of these commands with an argument as the name of a process, both of them return the exact same number. Are they the same commands? Are they two different commands that do the same thing? Is one of them an alias to the other?
pidof firefox
pgrep firefox
Best Answer
The programs
pgrep
andpidof
are not quite the same thing, but they are very similar. For example:As you can see,
pidof
failed to find a match for[i]ref
. This is becausepidof program
returns a list of all process IDs associated with a program calledprogram
. On the other hand,pgrep re
returns a list of all process IDs associated with a program whose name matches the regular expressionre
.In their most basic forms, the equivalence is actually:
As yet another concrete example, consider: