Skip to content

Instantly share code, notes, and snippets.

@eik3
Created April 22, 2011 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eik3/936362 to your computer and use it in GitHub Desktop.
Save eik3/936362 to your computer and use it in GitHub Desktop.
Process Grep Bash Function
function prg {
WIDE=""
if [ "$1" == "-w" ]
then
WIDE="www"
shift
fi
processes=$(pgrep -- "$1")
if [ ! -z "${processes}" ]
then
ps f${WIDE}u -p ${processes}
fi
}
@eik3
Copy link
Author

eik3 commented Apr 22, 2011

Example Output:

$ prg apache
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      3130  0.0  0.2  83232 13872 ?        Ss   Apr21   0:04 /usr/sbin/apache2 -k start
www-data  3135  0.0  0.2  82948 12996 ?        S    Apr21   0:00  \_ /usr/sbin/apache2 -k start
www-data  8209  0.4  0.3 155360 19828 ?        Sl   11:46   0:00  \_ /usr/sbin/apache2 -k start
www-data  8445  0.3  0.3 630044 20552 ?        Sl   11:46   0:00  \_ /usr/sbin/apache2 -k start
www-data  8583  0.0  0.3 628796 19256 ?        Sl   11:46   0:00  \_ /usr/sbin/apache2 -k start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment