aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/free.c35
-rw-r--r--procps/kill.c112
2 files changed, 119 insertions, 28 deletions
diff --git a/procps/free.c b/procps/free.c
new file mode 100644
index 000000000..36d357522
--- /dev/null
+++ b/procps/free.c
@@ -0,0 +1,35 @@
1/*
2 * Mini free implementation for busybox
3 *
4 * Copyright (C) 1999 by Lineo, inc.
5 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include "internal.h"
24#include <stdio.h>
25
26
27#if ! defined BB_FEATURE_USE_PROCFS
28#error Sorry, I depend on the /proc filesystem right now.
29#endif
30
31extern int free_main(int argc, char **argv)
32{
33 char* cmd[] = { "cat", "/proc/meminfo", "\0" };
34 exit(cat_main( 3, cmd));
35}
diff --git a/procps/kill.c b/procps/kill.c
index 8cc2b044e..0ba6d76ce 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -26,8 +26,14 @@
26#include <unistd.h> 26#include <unistd.h>
27#include <signal.h> 27#include <signal.h>
28#include <ctype.h> 28#include <ctype.h>
29#include <sys/stat.h>
30#include <unistd.h>
31
32static const char* kill_usage = "kill [-signal] process-id [process-id ...]\n\n"
33"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
34"Options:\n"
35"\t-l\tList all signal names and numbers.\n\n";
29 36
30const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n";
31 37
32struct signal_name { 38struct signal_name {
33 const char *name; 39 const char *name;
@@ -114,42 +120,92 @@ const struct signal_name signames[] = {
114extern int kill_main (int argc, char **argv) 120extern int kill_main (int argc, char **argv)
115{ 121{
116 int sig = SIGTERM; 122 int sig = SIGTERM;
123
124 argc--;
125 argv++;
126 /* Parse any options */
127 if (argc < 1)
128 usage(kill_usage);
117 129
118 if ( argc < 2 ) 130 while (argc > 0 && **argv == '-') {
119 usage (kill_usage); 131 while (*++(*argv)) {
132 switch (**argv) {
133 case 'l':
134 {
135 int col=0;
136 const struct signal_name *s = signames;
120 137
121 if ( **(argv+1) == '-' ) { 138 while (s->name != 0) {
122 if (isdigit( *(*(++argv)+1) )) { 139 col+=fprintf(stderr, "%2d) %-8s", s->number, (s++)->name);
123 sig = atoi (*argv); 140 if (col>60) {
124 if (sig < 0 || sig >= NSIG) 141 fprintf(stderr, "\n");
125 goto end; 142 col=0;
126 } 143 }
127 else { 144 }
128 const struct signal_name *s = signames; 145 fprintf(stderr, "\n\n");
129 while (s->name != 0) { 146 exit( TRUE);
130 if (strcasecmp (s->name, *argv+1) == 0) { 147 }
131 sig = s->number; 148 break;
132 break; 149 case '-':
150 usage(kill_usage);
151 default:
152 {
153 if (isdigit( **argv)) {
154 sig = atoi (*argv);
155 if (sig < 0 || sig >= NSIG)
156 goto end;
157 else {
158 argc--;
159 argv++;
160 goto do_it_now;
161 }
162 }
163 else {
164 const struct signal_name *s = signames;
165 while (s->name != 0) {
166 if (strcasecmp (s->name, *argv) == 0) {
167 sig = s->number;
168 argc--;
169 argv++;
170 goto do_it_now;
171 }
172 s++;
173 }
174 if (s->name == 0)
175 goto end;
176 }
133 } 177 }
134 s++;
135 } 178 }
136 if (s->name == 0) 179 argc--;
137 goto end; 180 argv++;
138 } 181 }
139 } 182 }
140 183
141 while (--argc > 1) { 184do_it_now:
142 int pid; 185
143 if (! isdigit( **(++argv))) { 186 while (argc >= 1) {
144 fprintf(stderr, "bad PID: %s\n", *argv); 187 int pid;
145 exit( FALSE); 188 struct stat statbuf;
146 } 189 char pidpath[20]="/proc/";
147 pid = atoi (*argv); 190
148 if (kill (pid, sig) != 0) { 191 if (! isdigit( **argv)) {
149 perror (*argv); 192 fprintf(stderr, "bad PID: %s\n", *argv);
150 exit ( FALSE); 193 exit( FALSE);
194 }
195 pid = atoi (*argv);
196 snprintf(pidpath, 20, "/proc/%s/stat", *argv);
197 if (stat( pidpath, &statbuf)!=0) {
198 fprintf(stderr, "kill: (%d) - No such pid\n", pid);
199 exit( FALSE);
151 } 200 }
201 if (kill (pid, sig) != 0) {
202 perror (*argv);
203 exit ( FALSE);
204 }
205 argv++;
152 } 206 }
207 exit ( TRUE);
208
153 209
154end: 210end:
155 fprintf(stderr, "bad signal name: %s\n", *argv); 211 fprintf(stderr, "bad signal name: %s\n", *argv);