Skip to content

Instantly share code, notes, and snippets.

@iandexter
Created May 28, 2010 02:24
Show Gist options
  • Save iandexter/416661 to your computer and use it in GitHub Desktop.
Save iandexter/416661 to your computer and use it in GitHub Desktop.
Search for a running process by PID or process name
#!/bin/sh
# Search for a running process.
EXPECTED_ARGS=1
usage() {
echo "Usage: `basename $0` process"
}
[ $# -ne $EXPECTED_ARGS ] && usage && exit 65
proc_str=$1
srch_str=$(echo $proc_str | sed 's/^\([a-zA-Z0-9]\)\(.*\)/\1\2/')
ps -eo user,pid,ppid,stime,time,cmd | grep "[S]TIME\|$srch_str" | grep -v "`basename $0`\|$$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment