Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does the -f option of pgrep do?

Status
Not open for further replies.

cpjust

Programmer
Sep 23, 2003
2,132
US
The man page for the -f option of pgrep says:
The regular expression pattern should be matched against the full process argument string (obtained from the pr_psargs field of the /proc/nnnnn/psinfo file). If no -f option is specified, the expression is matched only against the name of the executable file (obtained from the pr_fname field of the /proc/nnnnn/psinfo file).
But I'm not sure what that means.

What I thought it means is that the pattern you pass has to match the entire line in the CMD column of the ps command (including arguments), but that's not what I'm seeing.

When I run: 'ps -ef' here's part of the output:
Code:
cpjust    26024     1  0 May20 ?        00:00:00 /usr/lib/gvfs/gvfsd-smb --spawner :1.5 /org/gtk/gvfs/exec_spaw/5
cpjust    26045     1  0 May20 ?        00:00:00 /usr/lib/gvfs/gvfsd-smb-browse --spawner :1.5 /org/gtk/gvfs/exec_spaw/7
cpjust    26054     1  0 May20 ?        00:00:01 /usr/lib/gvfs/gvfsd-smb --spawner :1.5 /org/gtk/gvfs/exec_spaw/9
But when I run: 'pgrep -f smb' I see this:
Code:
26024
26045
26054
I would have expected it to not return anything (just like the -x option).

So what exactly is -f doing?
 
Hi

You have "smb" in the name of all three executable, so [tt]pgrep[/tt] will list all of them regardless the presence of the -f switch.

The difference would be in case the "smb" would be only in the arguments. Those would be listed only with -f.

Feherke.
 
Can you give me an example when pgrep acts differently with the -f switch than it does without it?
 
Nevermind, I figured it out.

Code:
pgrep -x exec_name
pgrep -f /full/path/to/exec_name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top