Skip to content
This repository
Browse code

Updating bin/pid to work more reliably.

  • Loading branch information...
commit 4572e4694e032837bcfece6c3b6f9245119515ee 1 parent 18ef9d6
Ben Alman authored

Showing 1 changed file with 7 additions and 5 deletions. Show diff stats Hide diff stats

  1. +7 5 bin/pid
12 bin/pid
@@ -4,18 +4,20 @@ if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
4 4 Get PIDs
5 5 http://benalman.com/
6 6
7   -Usage: $(basename "$0") [PID]
  7 +Usage: $(basename "$0") [processname [processname ...]]
8 8
9   -Get the PID(s) of matching process(es).
  9 +Get the PIDs of all matching processes for all specified processnames.
  10 +If no arguments are passed, list processes by PID, TTY, USER, COMMAND.
10 11
11   -Copyright (c) 2011 "Cowboy" Ben Alman
  12 +Copyright (c) 2012 "Cowboy" Ben Alman
12 13 Licensed under the MIT license.
13 14 http://benalman.com/about/license/
14 15 HELP
15 16 exit; fi
16 17
17 18 if [ ! "$1" ]; then
18   - ps axo pid,tty,user,command | sort -bdfk4
  19 + ps axo pid,tty,user,command
19 20 else
20   - echo $(ps axo pid,tty,user,command | grep -w "$@" | sort -g | awk '{print $1}')
  21 + args="$1"; shift; for arg in "$@"; do args="${args}|${arg}"; done
  22 + echo $(ps axo pid,tty,user,command | perl -nle"m#^\s*(\d+).*(?:$args)# && !m#.dotfiles/bin/pid# && print \$1")
21 23 fi

0 comments on commit 4572e46

Please sign in to comment.
Something went wrong with that request. Please try again.