diff options
author | Louis Sautier <sautier.louis@gmail.com> | 2021-11-04 13:55:16 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-10-14 14:33:34 +0200 |
commit | 707a7ef4c72d1d00ff61221511a70eada19185ca (patch) | |
tree | 3ba62983f3fbb00cba7f465d31a2e439acbbcdac | |
parent | c8c1fcdba163f264a503380bc63485aacd09214c (diff) | |
download | busybox-w32-707a7ef4c72d1d00ff61221511a70eada19185ca.tar.gz busybox-w32-707a7ef4c72d1d00ff61221511a70eada19185ca.tar.bz2 busybox-w32-707a7ef4c72d1d00ff61221511a70eada19185ca.zip |
pkill: add -e to display the name and PID of the process being killed
This mimics the behaviour of pkill -e / --echo from procps.
function old new delta
.rodata 105179 105200 +21
packed_usage 34523 34516 -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 21/-7) Total: 14 bytes
Signed-off-by: Louis Sautier <sautier.louis@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/pgrep.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/procps/pgrep.c b/procps/pgrep.c index 6d25c247e..82e00322f 100644 --- a/procps/pgrep.c +++ b/procps/pgrep.c | |||
@@ -44,7 +44,7 @@ | |||
44 | //usage: "\n -P Match parent process ID" | 44 | //usage: "\n -P Match parent process ID" |
45 | //usage: | 45 | //usage: |
46 | //usage:#define pkill_trivial_usage | 46 | //usage:#define pkill_trivial_usage |
47 | //usage: "[-l|-SIGNAL] [-xfvno] [-s SID|-P PPID|PATTERN]" | 47 | //usage: "[-l|-SIGNAL] [-xfvnoe] [-s SID|-P PPID|PATTERN]" |
48 | //usage:#define pkill_full_usage "\n\n" | 48 | //usage:#define pkill_full_usage "\n\n" |
49 | //usage: "Send signal to processes selected by regex PATTERN\n" | 49 | //usage: "Send signal to processes selected by regex PATTERN\n" |
50 | //usage: "\n -l List all signals" | 50 | //usage: "\n -l List all signals" |
@@ -55,6 +55,7 @@ | |||
55 | //usage: "\n -v Negate the match" | 55 | //usage: "\n -v Negate the match" |
56 | //usage: "\n -n Signal the newest process only" | 56 | //usage: "\n -n Signal the newest process only" |
57 | //usage: "\n -o Signal the oldest process only" | 57 | //usage: "\n -o Signal the oldest process only" |
58 | //usage: "\n -e Display name and PID of the process being killed" | ||
58 | 59 | ||
59 | #include "libbb.h" | 60 | #include "libbb.h" |
60 | #include "xregex.h" | 61 | #include "xregex.h" |
@@ -64,7 +65,7 @@ | |||
64 | #define pkill (ENABLE_PKILL && (!ENABLE_PGREP || applet_name[1] == 'k')) | 65 | #define pkill (ENABLE_PKILL && (!ENABLE_PGREP || applet_name[1] == 'k')) |
65 | 66 | ||
66 | enum { | 67 | enum { |
67 | /* "vlafxons:+P:+" */ | 68 | /* "vlafxones:+P:+" */ |
68 | OPTBIT_V = 0, /* must be first, we need OPT_INVERT = 0/1 */ | 69 | OPTBIT_V = 0, /* must be first, we need OPT_INVERT = 0/1 */ |
69 | OPTBIT_L, | 70 | OPTBIT_L, |
70 | OPTBIT_A, | 71 | OPTBIT_A, |
@@ -72,6 +73,7 @@ enum { | |||
72 | OPTBIT_X, | 73 | OPTBIT_X, |
73 | OPTBIT_O, | 74 | OPTBIT_O, |
74 | OPTBIT_N, | 75 | OPTBIT_N, |
76 | OPTBIT_E, /* should be pkill-only, do we care? */ | ||
75 | OPTBIT_S, | 77 | OPTBIT_S, |
76 | OPTBIT_P, | 78 | OPTBIT_P, |
77 | }; | 79 | }; |
@@ -83,6 +85,7 @@ enum { | |||
83 | #define OPT_ANCHOR (opt & (1 << OPTBIT_X)) | 85 | #define OPT_ANCHOR (opt & (1 << OPTBIT_X)) |
84 | #define OPT_FIRST (opt & (1 << OPTBIT_O)) | 86 | #define OPT_FIRST (opt & (1 << OPTBIT_O)) |
85 | #define OPT_LAST (opt & (1 << OPTBIT_N)) | 87 | #define OPT_LAST (opt & (1 << OPTBIT_N)) |
88 | #define OPT_ECHO (opt & (1 << OPTBIT_E)) | ||
86 | #define OPT_SID (opt & (1 << OPTBIT_S)) | 89 | #define OPT_SID (opt & (1 << OPTBIT_S)) |
87 | #define OPT_PPID (opt & (1 << OPTBIT_P)) | 90 | #define OPT_PPID (opt & (1 << OPTBIT_P)) |
88 | 91 | ||
@@ -93,8 +96,12 @@ static void act(unsigned pid, char *cmd, int signo) | |||
93 | printf("%u %s\n", pid, cmd); | 96 | printf("%u %s\n", pid, cmd); |
94 | else | 97 | else |
95 | printf("%u\n", pid); | 98 | printf("%u\n", pid); |
96 | } else | 99 | } else { |
97 | kill(pid, signo); | 100 | kill(pid, signo); |
101 | if (option_mask32 & (1 << OPTBIT_E)) { | ||
102 | printf("%s killed (pid %u)\n", cmd, pid); | ||
103 | } | ||
104 | } | ||
98 | } | 105 | } |
99 | 106 | ||
100 | int pgrep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 107 | int pgrep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -131,7 +138,7 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv) | |||
131 | /* Parse remaining options */ | 138 | /* Parse remaining options */ |
132 | ppid2match = -1; | 139 | ppid2match = -1; |
133 | sid2match = -1; | 140 | sid2match = -1; |
134 | opt = getopt32(argv, "vlafxons:+P:+", &sid2match, &ppid2match); | 141 | opt = getopt32(argv, "vlafxones:+P:+", &sid2match, &ppid2match); |
135 | argv += optind; | 142 | argv += optind; |
136 | 143 | ||
137 | if (pkill && OPT_LIST) { /* -l: print the whole signal list */ | 144 | if (pkill && OPT_LIST) { /* -l: print the whole signal list */ |