Debian Codegraph @

ctdb/tests/UNIT/eventscripts/stubs/ps

raw
1 #!/bin/sh
2
3 usage()
4 {
5 echo "ps [ -p PID | -o FORMAT | aufxww ]"
6 exit 1
7 }
8
9 while getopts "o:p:h:?" opt; do
10 case "$opt" in
11 o) format="$OPTARG" ;;
12 p) pid="$OPTARG" ;;
13 \? | h) usage ;;
14 esac
15 done
16 shift $((OPTIND - 1))
17
18 if [ -n "$pid" ] && [ -n "$FAKE_PS_MAP" ]; then
19 # shellcheck disable=SC1001
20 case "$format" in
21 comm\=)
22 echo "$FAKE_PS_MAP" |
23 awk -v pid="$pid" '$1 == pid { print $2 }'
24 ;;
25 state\=)
26 echo "$FAKE_PS_MAP" |
27 awk -v pid="$pid" '$1 == pid { print $3 }'
28 ;;
29 esac
30
31 exit
32 fi
33
34 if [ "$1" != "auxfww" ]; then
35 echo "option $1 not supported"
36 usage
37 fi
38
39 cat <<EOF
40 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
41 root 2 0.0 0.0 0 0 ? S Aug28 0:00 [kthreadd]
42 root 3 0.0 0.0 0 0 ? S Aug28 0:43 \_ [ksoftirqd/0]
43 ...
44 root 1 0.0 0.0 2976 624 ? Ss Aug28 0:07 init [2]
45 root 495 0.0 0.0 3888 1640 ? Ss Aug28 0:00 udevd --daemon
46 ...
47 [MORE FAKE ps OUTPUT]
48 EOF