Can the Linux ps command output be filtered by user AND command?

I need the pid for a process given its owner and its command. I can filter a process per user with "ps -u xxx" and its command by "ps -C yyy", but when I try "ps -u xxx -C yyy", they are combined using OR logic. I need AND logic. How can I accomplish this?


Solution 1:

Use pgrep?

pgrep -U xxx yyy

it returns just the pid (or pids, if more than one process matches).

Solution 2:

Use grep?

ps -u xxx | grep yyy | grep -v grep