Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to get "pgrep" to give me all the info about each process that "ps" does? I know I can pipe "ps" through "grep" but that's a lot of typing and it also gives me the "grep" process itself which I don't want.

share|improve this question
up vote 8 down vote accepted

pgrep's output options are pretty limited. You will almost certainly need to send it back through ps to get the important information out. You could automate this by using a bash function in your ~/.bashrc.

function ppgrep() { pgrep "$@" | xargs --no-run-if-empty ps fp; }

Then call the command with.

ppgrep <pattern>
share|improve this answer
2  
Thanks! I modified it to: function ppgrep() { pgrep "$@" | xargs ps fp 2> /dev/null; } Otherwise, if no processes match your search, it dumps a whole ps usage megilla. – JoelFan Dec 10 '10 at 4:17
    
On OS X, the ps needs a hyphen for the flags: function ppgrep() { pgrep "$@" | xargs ps -fp 2> /dev/null; } – Erik Nomitch Sep 29 '15 at 11:34
    
If you want to avoid the ps usage page, GNU xargs has an option, -r that will only execute the command if it has received a list. – Doug Apr 22 at 3:19

Combine pgrep with ps using xargs!

pgrep <your pgrep-criteria> | xargs ps <your ps options> -p

For example try

pgrep -u user | xargs ps -f -p

to get a full process list of user.

It's nice that you keep the first line with the column names. grep always drops the column names.

share|improve this answer
    
excellent! this resolves a strange problem with arcgis server startup script for xfvb – prusswan Jul 17 '14 at 11:25

Most linuxes use procps-ng. Since 3.3.4 (released in 2012), pgrep -a (--list-full) shows the full command line.
Note: By default pgrep only matches the pattern you give against the executable name. If you want to match against the full command line (as grepping ps does), add the -f (--full) option.

In older versions (including the original procps project), -l option showed info but it's behavior varied:

  • pgrep -fl matched the pattern against full command line and showed the full command line.
  • pgrep -l alone matched only executable name and showed only executable name.
    If you don't want full match, you couldn't see the full command line :-( [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=526355#15]

Not sure what code *BSD use but their man page documents the old -fl behavior.

Unfortunately you can't even use -fl portably - in recent procps-ng, -f (--list-name) always prints only the executable name.

share|improve this answer

I don't think there is, the most information you can get is the name and process id by using the -l option to pgrep.

ps supports all sorts of formatting options, so I would just make an alias for what you want to save the typing. A simple way to exclude the grep process from the output us to include an additional pipe to grep -v grep to exclude any grep processes.

share|improve this answer

Use the -v option to grep - it returns everything BUT the requested pattern.

ps -ef | grep <process> | grep -v grep
share|improve this answer

In order to eliminate the grep process, you can use brackets as part of your pattern:

ps -ef | grep '[t]ty'

You can do this with ps and pgrep:

ps -fp $(pgrep -d, tty)
share|improve this answer

This will help you I guess:

ps auxww

share|improve this answer
2  
Can you please elaborate. More info would improve this answer – Dave M Jul 23 '15 at 15:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.