forked from cowboy/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpid
More file actions
executable file
·23 lines (18 loc) · 670 Bytes
/
pid
File metadata and controls
executable file
·23 lines (18 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env bash
if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
Get PIDs
http://benalman.com/
Usage: $(basename "$0") [processname [processname ...]]
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) 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
else
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