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
51 testing "-s 0 -f pattern (regexp)" "pkill -s 0 -f ye* && sleep 1 &&
52 (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
69 testing "-o pattern" "pkill -o yes && sleep 1 && pgrep yes" \
71 killall yes >/dev/null 2>&1
75 testing "-s (blank) pattern" "pkill -s '' yes && sleep 1 &&
76 (pgrep yes || echo 'yes')" "yes\n" "" ""
77 killall yes >/dev/null 2>&1
81 testing "-s 0 pattern" "pkill -s 0 yes && sleep 1 &&
82 (pgrep yes || echo 'yes')" "yes\n" "" ""
83 killall yes >/dev/null 2>&1
87 proc_p=`cat /proc/${proc}/stat | awk '{ print $4 }'`
89 testing "-P parent_prodId pattern" "pkill -P $proc_p yes && sleep 1 &&
90 (pgrep yes || echo 'yes')" "yes\n" "" ""
91 killall yes >/dev/null 2>&1
95 proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'`
97 testing "-9 pattern" "pkill -9 yes && sleep 1 &&
98 (pgrep yes || echo 'yes')" "yes\n" "" ""
99 killall yes >/dev/null 2>&1