diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-07-31 19:06:07 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-07-31 19:06:07 +0000 |
commit | 221b2ea6c40e5b2e0123a0c9a4ba6e74d86eb33f (patch) | |
tree | 9fc861b2a801e9a95308474eb9f9af0ab1084e75 | |
parent | 9a53feaa76840ef21bef864244d95b5ac6923658 (diff) | |
download | busybox-w32-221b2ea6c40e5b2e0123a0c9a4ba6e74d86eb33f.tar.gz busybox-w32-221b2ea6c40e5b2e0123a0c9a4ba6e74d86eb33f.tar.bz2 busybox-w32-221b2ea6c40e5b2e0123a0c9a4ba6e74d86eb33f.zip |
I just wrote up a simple pidof applet, closing bug #1197
-Erik
-rw-r--r-- | Changelog | 1 | ||||
-rw-r--r-- | Config.h | 1 | ||||
-rw-r--r-- | applets.h | 3 | ||||
-rw-r--r-- | applets/usage.h | 8 | ||||
-rw-r--r-- | include/applets.h | 3 | ||||
-rw-r--r-- | include/usage.h | 8 | ||||
-rw-r--r-- | pidof.c | 79 | ||||
-rw-r--r-- | procps/pidof.c | 79 | ||||
-rw-r--r-- | usage.h | 8 |
9 files changed, 190 insertions, 0 deletions
@@ -13,6 +13,7 @@ | |||
13 | New Applets: | 13 | New Applets: |
14 | * David McCullough <davidm@lineo.com> -- modprobe | 14 | * David McCullough <davidm@lineo.com> -- modprobe |
15 | * Vladimir Oleynik -- traceroute | 15 | * Vladimir Oleynik -- traceroute |
16 | * Erik Andersen -- pidof | ||
16 | 17 | ||
17 | New Scripts: | 18 | New Scripts: |
18 | * David Schleef, Erik Andersen, Stuart Hughes -- depmod.pl | 19 | * David Schleef, Erik Andersen, Stuart Hughes -- depmod.pl |
@@ -82,6 +82,7 @@ | |||
82 | #define BB_MV | 82 | #define BB_MV |
83 | //#define BB_NC | 83 | //#define BB_NC |
84 | //#define BB_NSLOOKUP | 84 | //#define BB_NSLOOKUP |
85 | #define BB_PIDOF | ||
85 | //#define BB_PING | 86 | //#define BB_PING |
86 | //#define BB_PIVOT_ROOT | 87 | //#define BB_PIVOT_ROOT |
87 | #define BB_POWEROFF | 88 | #define BB_POWEROFF |
@@ -284,6 +284,9 @@ | |||
284 | #ifdef BB_NSLOOKUP | 284 | #ifdef BB_NSLOOKUP |
285 | APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN) | 285 | APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN) |
286 | #endif | 286 | #endif |
287 | #ifdef BB_PIDOF | ||
288 | APPLET(pidof, pidof_main, _BB_DIR_BIN) | ||
289 | #endif | ||
287 | #ifdef BB_PING | 290 | #ifdef BB_PING |
288 | APPLET(ping, ping_main, _BB_DIR_BIN) | 291 | APPLET(ping, ping_main, _BB_DIR_BIN) |
289 | #endif | 292 | #endif |
diff --git a/applets/usage.h b/applets/usage.h index 2a2042292..08da42b27 100644 --- a/applets/usage.h +++ b/applets/usage.h | |||
@@ -1190,6 +1190,14 @@ | |||
1190 | "Name: debian\n" \ | 1190 | "Name: debian\n" \ |
1191 | "Address: 127.0.0.1\n" | 1191 | "Address: 127.0.0.1\n" |
1192 | 1192 | ||
1193 | #define pidof_trivial_usage \ | ||
1194 | "process-name [process-name ...]" | ||
1195 | #define pidof_full_usage \ | ||
1196 | "Lists the PIDs of all processes with names that match the names on the command line" | ||
1197 | #define pidof_example_usage \ | ||
1198 | "$ pidof init\n" \ | ||
1199 | "1\n" | ||
1200 | |||
1193 | #ifndef BB_FEATURE_FANCY_PING | 1201 | #ifndef BB_FEATURE_FANCY_PING |
1194 | #define ping_trivial_usage "host" | 1202 | #define ping_trivial_usage "host" |
1195 | #define ping_full_usage "Send ICMP ECHO_REQUEST packets to network hosts" | 1203 | #define ping_full_usage "Send ICMP ECHO_REQUEST packets to network hosts" |
diff --git a/include/applets.h b/include/applets.h index 9fc59cda5..0786c39eb 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -284,6 +284,9 @@ | |||
284 | #ifdef BB_NSLOOKUP | 284 | #ifdef BB_NSLOOKUP |
285 | APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN) | 285 | APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN) |
286 | #endif | 286 | #endif |
287 | #ifdef BB_PIDOF | ||
288 | APPLET(pidof, pidof_main, _BB_DIR_BIN) | ||
289 | #endif | ||
287 | #ifdef BB_PING | 290 | #ifdef BB_PING |
288 | APPLET(ping, ping_main, _BB_DIR_BIN) | 291 | APPLET(ping, ping_main, _BB_DIR_BIN) |
289 | #endif | 292 | #endif |
diff --git a/include/usage.h b/include/usage.h index 2a2042292..08da42b27 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1190,6 +1190,14 @@ | |||
1190 | "Name: debian\n" \ | 1190 | "Name: debian\n" \ |
1191 | "Address: 127.0.0.1\n" | 1191 | "Address: 127.0.0.1\n" |
1192 | 1192 | ||
1193 | #define pidof_trivial_usage \ | ||
1194 | "process-name [process-name ...]" | ||
1195 | #define pidof_full_usage \ | ||
1196 | "Lists the PIDs of all processes with names that match the names on the command line" | ||
1197 | #define pidof_example_usage \ | ||
1198 | "$ pidof init\n" \ | ||
1199 | "1\n" | ||
1200 | |||
1193 | #ifndef BB_FEATURE_FANCY_PING | 1201 | #ifndef BB_FEATURE_FANCY_PING |
1194 | #define ping_trivial_usage "host" | 1202 | #define ping_trivial_usage "host" |
1195 | #define ping_full_usage "Send ICMP ECHO_REQUEST packets to network hosts" | 1203 | #define ping_full_usage "Send ICMP ECHO_REQUEST packets to network hosts" |
diff --git a/pidof.c b/pidof.c new file mode 100644 index 000000000..50dffd387 --- /dev/null +++ b/pidof.c | |||
@@ -0,0 +1,79 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * pidof implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2001 by Lineo, inc. | ||
6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <errno.h> | ||
28 | #include <unistd.h> | ||
29 | #include <signal.h> | ||
30 | #include <ctype.h> | ||
31 | #include <string.h> | ||
32 | #include <unistd.h> | ||
33 | #include "busybox.h" | ||
34 | |||
35 | |||
36 | extern int pidof_main(int argc, char **argv) | ||
37 | { | ||
38 | int opt; | ||
39 | |||
40 | |||
41 | /* do normal option parsing */ | ||
42 | while ((opt = getopt(argc, argv, "ne:f:")) > 0) { | ||
43 | switch (opt) { | ||
44 | #if 0 | ||
45 | case 'g': | ||
46 | break; | ||
47 | case 'e': | ||
48 | break; | ||
49 | #endif | ||
50 | default: | ||
51 | show_usage(); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /* if we didn't get a process name, then we need to choke and die here */ | ||
56 | if (argv[optind] == NULL) | ||
57 | show_usage(); | ||
58 | |||
59 | /* Looks like everything is set to go. */ | ||
60 | while(optind < argc) { | ||
61 | pid_t* pidList; | ||
62 | |||
63 | pidList = find_pid_by_name( argv[optind]); | ||
64 | if (!pidList || *pidList<=0) { | ||
65 | break; | ||
66 | } | ||
67 | |||
68 | for(; pidList && *pidList!=0; pidList++) { | ||
69 | printf("%ld ", (long)*pidList); | ||
70 | } | ||
71 | /* Note that we don't bother to free the memory | ||
72 | * allocated in find_pid_by_name(). It will be freed | ||
73 | * upon exit, so we can save a byte or two */ | ||
74 | optind++; | ||
75 | } | ||
76 | printf("\n"); | ||
77 | |||
78 | return EXIT_SUCCESS; | ||
79 | } | ||
diff --git a/procps/pidof.c b/procps/pidof.c new file mode 100644 index 000000000..50dffd387 --- /dev/null +++ b/procps/pidof.c | |||
@@ -0,0 +1,79 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * pidof implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 2001 by Lineo, inc. | ||
6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <errno.h> | ||
28 | #include <unistd.h> | ||
29 | #include <signal.h> | ||
30 | #include <ctype.h> | ||
31 | #include <string.h> | ||
32 | #include <unistd.h> | ||
33 | #include "busybox.h" | ||
34 | |||
35 | |||
36 | extern int pidof_main(int argc, char **argv) | ||
37 | { | ||
38 | int opt; | ||
39 | |||
40 | |||
41 | /* do normal option parsing */ | ||
42 | while ((opt = getopt(argc, argv, "ne:f:")) > 0) { | ||
43 | switch (opt) { | ||
44 | #if 0 | ||
45 | case 'g': | ||
46 | break; | ||
47 | case 'e': | ||
48 | break; | ||
49 | #endif | ||
50 | default: | ||
51 | show_usage(); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /* if we didn't get a process name, then we need to choke and die here */ | ||
56 | if (argv[optind] == NULL) | ||
57 | show_usage(); | ||
58 | |||
59 | /* Looks like everything is set to go. */ | ||
60 | while(optind < argc) { | ||
61 | pid_t* pidList; | ||
62 | |||
63 | pidList = find_pid_by_name( argv[optind]); | ||
64 | if (!pidList || *pidList<=0) { | ||
65 | break; | ||
66 | } | ||
67 | |||
68 | for(; pidList && *pidList!=0; pidList++) { | ||
69 | printf("%ld ", (long)*pidList); | ||
70 | } | ||
71 | /* Note that we don't bother to free the memory | ||
72 | * allocated in find_pid_by_name(). It will be freed | ||
73 | * upon exit, so we can save a byte or two */ | ||
74 | optind++; | ||
75 | } | ||
76 | printf("\n"); | ||
77 | |||
78 | return EXIT_SUCCESS; | ||
79 | } | ||
@@ -1190,6 +1190,14 @@ | |||
1190 | "Name: debian\n" \ | 1190 | "Name: debian\n" \ |
1191 | "Address: 127.0.0.1\n" | 1191 | "Address: 127.0.0.1\n" |
1192 | 1192 | ||
1193 | #define pidof_trivial_usage \ | ||
1194 | "process-name [process-name ...]" | ||
1195 | #define pidof_full_usage \ | ||
1196 | "Lists the PIDs of all processes with names that match the names on the command line" | ||
1197 | #define pidof_example_usage \ | ||
1198 | "$ pidof init\n" \ | ||
1199 | "1\n" | ||
1200 | |||
1193 | #ifndef BB_FEATURE_FANCY_PING | 1201 | #ifndef BB_FEATURE_FANCY_PING |
1194 | #define ping_trivial_usage "host" | 1202 | #define ping_trivial_usage "host" |
1195 | #define ping_full_usage "Send ICMP ECHO_REQUEST packets to network hosts" | 1203 | #define ping_full_usage "Send ICMP ECHO_REQUEST packets to network hosts" |