3 # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
4 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
6 #cleaning 'yes' processes
7 killall yes >/dev/null 2>&1
9 [ -f testing.sh ] && . testing.sh
11 #testing "name" "command" "result" "infile" "stdin"
13 # Starting processes to test pgrep command
16 echo "# Process created with id: $proc"
19 proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'`
20 echo "# Parent Process id of $proc is $proc_parent"
22 # Testcases for pgrep command
23 testing "pgrep pattern" "pgrep yes" "$proc\n" "" ""
24 testing "pgrep wildCardPattern" "pgrep ^y.*s$" "$proc\n" "" ""
25 testing "pgrep -l pattern" "pgrep -l yes" "$proc yes\n" "" ""
26 testing "pgrep -f pattern" "pgrep -f yes" "$proc\n" "" ""
27 testing "pgrep -n pattern" "pgrep -n yes" "$proc\n" "" ""
28 testing "pgrep -o pattern" "pgrep -o yes" "$proc\n" "" ""
29 testing "pgrep -s" "pgrep -s $session_id yes" "$proc\n" "" ""
30 testing "pgrep -P" "pgrep -P $proc_parent yes" "$proc\n" "" ""
33 killall yes >/dev/null 2>&1
35 # Testcases for pkill command
39 testing "pkill pattern" "pkill yes && sleep 1 && (pgrep yes || echo 'yes')" \
41 killall yes >/dev/null 2>&1
44 yes print1 >/dev/null &
45 yes print2 >/dev/null &
47 testing "pkill pattern (multiple)" "pkill yes && sleep 1 &&
48 (pgrep yes || echo 'yes')" "yes\n" "" ""
49 killall yes >/dev/null 2>&1
53 testing "pkill -f pattern (one)" "pkill -f yes && sleep 1 &&
54 (pgrep yes || echo 'yes')" "yes\n" "" ""
55 killall yes >/dev/null 2>&1
57 yes print1 >/dev/null &
59 testing "pkill -f pattern args" "pkill -f \"yes print1\" && sleep 1 &&
60 (pgrep yes || echo 'yes')" "yes\n" "" ""
61 killall yes >/dev/null 2>&1
64 yes print1 >/dev/null &
65 yes print2 >/dev/null &
67 testing "pkill -f pattern (multiple)" "pkill -f yes && sleep 1 &&
68 (pgrep yes || echo 'yes')" "yes\n" "" ""
69 killall yes >/dev/null 2>&1
73 testing "pkill -s 0 -f pattern (regexp)" "pkill -s 0 -f ye* && sleep 1 &&
74 (pgrep yes || echo 'yes')" "yes\n" "" ""
75 killall yes >/dev/null 2>&1
82 testing "pkill -n pattern" "pkill -n yes && sleep 1 && pgrep yes" \
84 killall yes >/dev/null 2>&1
91 testing "pkill -o pattern" "pkill -o yes && sleep 1 && pgrep yes" \
93 killall yes >/dev/null 2>&1
97 testing "pkill -s (blank) pattern" "pkill -s '' yes && sleep 1 &&
98 (pgrep yes || echo 'yes')" "yes\n" "" ""
99 killall yes >/dev/null 2>&1
103 testing "pkill -s 0 pattern" "pkill -s 0 yes && sleep 1 &&
104 (pgrep yes || echo 'yes')" "yes\n" "" ""
105 killall yes >/dev/null 2>&1
109 proc_p=`cat /proc/${proc}/stat | awk '{ print $4 }'`
111 testing "pkill -P parent_prodId pattern" "pkill -P $proc_p yes && sleep 1 &&
112 (pgrep yes || echo 'yes')" "yes\n" "" ""
113 killall yes >/dev/null 2>&1
117 proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'`
119 testing "pkill -9 pattern" "pkill -9 yes && sleep 1 &&
120 (pgrep yes || echo 'yes')" "yes\n" "" ""
121 killall yes >/dev/null 2>&1