How to filter processes with "ps" to match all conditions?

1

In Linux, if I use ps --user john -C processname, then I get all processes owned by the user and in addition all processes named processname.

Is there a way to modify the behavior to get only processes called processname owned by john?

Black

Posted 2015-02-24T07:06:34.043

Reputation: 173

Answers

1

Unfortunately ps is a bit strange in that way. You can use pgrep to help ps. In pgrep all conditions must match. Use that syntax for example:

ps -p"$(pgrep -d, -u john processname)"

pgrep prints all the pids comma separated that match the conditions. That is given to ps as an argument to the -p flag. -p selects a list of pids.

chaos

Posted 2015-02-24T07:06:34.043

Reputation: 3 704