Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

5 Answers

up vote 5 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 ps fp; }

Then call the command with.

ppgrep <pattern>
share|improve this answer
    
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
add comment

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
add comment

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
add comment

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

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

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
add comment

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.