linux

Filter a list of processes that match a given string in a Unix shell

A list of all current processes that match a given string and belong to the current user can be generated using the following command.

$ ps -x | grep node
4066 ttys000    0:00.07 node index.js
4219 ttys000    0:00.00 grep node

ps will return a snapshot of the current processes. The -x flag will limit the returned processes to those owned by the current user (the same EUID as ps). The pipe | connects the output of ps -x to grep node, which filters the output so that only lines containing the string node are returned.

more Linux posts