Skip to content

Instantly share code, notes, and snippets.

@antmd
Created November 23, 2013 18:29
Show Gist options
  • Save antmd/7618216 to your computer and use it in GitHub Desktop.
Save antmd/7618216 to your computer and use it in GitHub Desktop.
Find processes matching name
#!/bin/bash
if [ $# -lt 1 ]; then
exit 1
fi
PROG_NAME=$1
PROGS=$(ps -u$USER -eww -opid,ucomm | grep -i $PROG_NAME | grep -v grep | tr '\n' ':')
_IFS=$IFS
IFS=:
set - $PROGS
if [ $# -eq 0 ]; then
echo "Could not find a match for '$PROG_NAME'" >&2
exit 1
else
for PROG in $PROGS; do
echo "$PROG"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment