Skip to content

Commit

Permalink
Updating bin/pid to work more reliably.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy committed Jan 4, 2012
1 parent 18ef9d6 commit 4572e46
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bin/pid
Expand Up @@ -4,18 +4,20 @@ if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
Get PIDs
http://benalman.com/
Usage: $(basename "$0") [PID]
Usage: $(basename "$0") [processname [processname ...]]
Get the PID(s) of matching process(es).
Get the PIDs of all matching processes for all specified processnames.
If no arguments are passed, list processes by PID, TTY, USER, COMMAND.
Copyright (c) 2011 "Cowboy" Ben Alman
Copyright (c) 2012 "Cowboy" Ben Alman
Licensed under the MIT license.
http://benalman.com/about/license/
HELP
exit; fi

if [ ! "$1" ]; then
ps axo pid,tty,user,command | sort -bdfk4
ps axo pid,tty,user,command
else
echo $(ps axo pid,tty,user,command | grep -w "$@" | sort -g | awk '{print $1}')
args="$1"; shift; for arg in "$@"; do args="${args}|${arg}"; done
echo $(ps axo pid,tty,user,command | perl -nle"m#^\s*(\d+).*(?:$args)# && !m#.dotfiles/bin/pid# && print \$1")
fi

0 comments on commit 4572e46

Please sign in to comment.