Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating bin/pid to work more reliably.

  • Loading branch information...
commit 4572e4694e032837bcfece6c3b6f9245119515ee 1 parent 18ef9d6
@cowboy authored
Showing with 7 additions and 5 deletions.
  1. +7 −5 bin/pid
View
12 bin/pid
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.