aboutsummaryrefslogtreecommitdiff
path: root/tests/pkill.test
blob: 7a20ae5cfff40380aa7fdc92d88bcb1234e9c99f (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash

# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>

#cleaning 'yes' processes
killall yes >/dev/null 2>&1

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

# Testcases for pkill command

yes >/dev/null &
sleep 1
testing "pattern" "pkill yes && sleep 1 && (pgrep yes || echo 'yes')" \
  "yes\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
yes print1 >/dev/null &
yes print2 >/dev/null &
sleep 1
testing "pattern (multiple)" "pkill yes && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
sleep 1
testing "-f pattern (one)" "pkill -f yes && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1

yes print1 >/dev/null &
sleep 1
testing "-f pattern args" "pkill -f \"yes print1\" && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
yes print1 >/dev/null &
yes print2 >/dev/null &
sleep 1
testing "-f pattern (multiple)" "pkill -f yes && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
sleep 1
testing "-s 0 -f pattern (regexp)" "pkill -s 0 -f ye* && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
proc1=$!
yes >/dev/null &
proc2=$!
sleep 1
testing "-n pattern" "pkill -n yes && sleep 1 && pgrep yes" \
  "$proc1\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
proc1=$!
yes >/dev/null &
proc2=$!
sleep 1
testing "-o pattern" "pkill -o yes && sleep 1 && pgrep yes" \
  "$proc2\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
sleep 1
testing "-s (blank) pattern" "pkill -s '' yes && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
sleep 1
testing "-s 0 pattern" "pkill -s 0 yes && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
proc=$!
proc_p=`cat /proc/${proc}/stat | awk '{ print $4 }'`
sleep 1
testing "-P parent_prodId pattern" "pkill -P $proc_p yes && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1

yes >/dev/null &
proc=$!
proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'`
sleep 1
testing "-9 pattern" "pkill -9 yes && sleep 1 &&
   (pgrep yes || echo 'yes')" "yes\n" "" ""
killall yes >/dev/null 2>&1