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 # Testcases for pkill command
17 testing "pattern" "pkill yes && sleep 1 && (pgrep yes || echo 'yes')" \
19 killall yes >/dev/null 2>&1
22 yes print1 >/dev/null &
23 yes print2 >/dev/null &
25 testing "pattern (multiple)" "pkill yes && sleep 1 &&
26 (pgrep yes || echo 'yes')" "yes\n" "" ""
27 killall yes >/dev/null 2>&1
31 testing "-f pattern (one)" "pkill -f yes && sleep 1 &&
32 (pgrep yes || echo 'yes')" "yes\n" "" ""
33 killall yes >/dev/null 2>&1
35 yes print1 >/dev/null &
37 testing "-f pattern args" "pkill -f \"yes print1\" && sleep 1 &&
38 (pgrep yes || echo 'yes')" "yes\n" "" ""
39 killall yes >/dev/null 2>&1
42 yes print1 >/dev/null &
43 yes print2 >/dev/null &
45 testing "-f pattern (multiple)" "pkill -f yes && sleep 1 &&
46 (pgrep yes || echo 'yes')" "yes\n" "" ""
47 killall yes >/dev/null 2>&1
49 yes this-is-unlikely-to-appear-otherwise >/dev/null &
51 testing "-s 0 -f pattern (regexp)" "pkill -s 0 -f .*-unlikely-.*-otherwise &&
52 sleep 1 && (pgrep yes || echo 'yes')" "yes\n" "" ""
53 killall yes >/dev/null 2>&1
60 testing "-n pattern" "pkill -n yes && sleep 1 && pgrep yes" \
62 killall yes >/dev/null 2>&1
70 testing "-o pattern" "pkill -o yes && sleep 1 && pgrep yes" \
72 killall yes >/dev/null 2>&1
76 testing "-s (blank) pattern" "pkill -s '' yes && sleep 1 &&
77 (pgrep yes || echo 'yes')" "yes\n" "" ""
78 killall yes >/dev/null 2>&1
82 testing "-s 0 pattern" "pkill -s 0 yes && sleep 1 &&
83 (pgrep yes || echo 'yes')" "yes\n" "" ""
84 killall yes >/dev/null 2>&1
88 proc_p=`cat /proc/${proc}/stat | cut -d' ' -f4`
90 testing "-P parent_prodId pattern" "pkill -P $proc_p yes && sleep 1 &&
91 (pgrep yes || echo 'yes')" "yes\n" "" ""
92 killall yes >/dev/null 2>&1
96 testing "-9 pattern" "pkill -9 yes && sleep 1 &&
97 (pgrep yes || echo 'yes')" "yes\n" "" ""
98 killall yes >/dev/null 2>&1
102 testing "return success" "pkill yes && echo success" "success\n" "" ""
103 killall yes >/dev/null 2>&1
105 testing "return failure" "pkill almost-certainly-not || echo failure" \