-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpid
executable file
·73 lines (63 loc) · 1.7 KB
/
pid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
##############################################################################
#
# NAME: pid
#
# DESCRIPTION: Show all the processes owned by me that match certain name
# criteria.
#
# USAGE: pid [-n] [PATTERN]
# -n Does not show the ps header
# PATTERN A pattern to match the process names. If no pattern
# is specified, all user's processes are shown.
#
# DEPENDENCIES: None
#
##############################################################################
#
#-----------------------------------------------------------------------------
usage()
{
sed -e 's/^ //' <<'USAGE'
Usage:
pid [-n] [PATTERN]
-n Does not show the ps header
PATTERN A pattern to match the process names. If no pattern
is specified, all user's processes are shown.
USAGE
exit $1
}
#-----------------------------------------------------------------------------
# Only asking for help
[[ $1 = '-h' ]] && usage 0
# Headers or not?
if [[ $1 = -n ]]; then
showheader=0
shift
else
showheader=1
fi
# The meat!
ps aux -u $USER -U $USER | awk \
-v proc="$1" \
-v showheader="$showheader" \
-v shell_pid="$$" \
'
{
/* If header is requested, save it just in case */
if (showheader == 1 && NR == 1)
{
header = $0;
}
awk_pid = PROCINFO["pid"];
if ( ($0 ~ proc) && ($2 != awk_pid) && ($2 != shell_pid) )
{
if (showheader == 1)
{
showheader = 0;
print header;
}
print $0;
}
}'
# vim: fdm=marker :