From 221b2ea6c40e5b2e0123a0c9a4ba6e74d86eb33f Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 31 Jul 2001 19:06:07 +0000 Subject: [PATCH] I just wrote up a simple pidof applet, closing bug #1197 -Erik --- Changelog | 1 + Config.h | 1 + applets.h | 3 ++ applets/usage.h | 8 +++++ include/applets.h | 3 ++ include/usage.h | 8 +++++ pidof.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ procps/pidof.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ usage.h | 8 +++++ 9 files changed, 190 insertions(+) create mode 100644 pidof.c create mode 100644 procps/pidof.c diff --git a/Changelog b/Changelog index 165736f5f..efd593ad6 100644 --- a/Changelog +++ b/Changelog @@ -13,6 +13,7 @@ New Applets: * David McCullough -- modprobe * Vladimir Oleynik -- traceroute + * Erik Andersen -- pidof New Scripts: * David Schleef, Erik Andersen, Stuart Hughes -- depmod.pl diff --git a/Config.h b/Config.h index f753401de..4523fbcab 100644 --- a/Config.h +++ b/Config.h @@ -82,6 +82,7 @@ #define BB_MV //#define BB_NC //#define BB_NSLOOKUP +#define BB_PIDOF //#define BB_PING //#define BB_PIVOT_ROOT #define BB_POWEROFF diff --git a/applets.h b/applets.h index 9fc59cda5..0786c39eb 100644 --- a/applets.h +++ b/applets.h @@ -284,6 +284,9 @@ #ifdef BB_NSLOOKUP APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN) #endif +#ifdef BB_PIDOF + APPLET(pidof, pidof_main, _BB_DIR_BIN) +#endif #ifdef BB_PING APPLET(ping, ping_main, _BB_DIR_BIN) #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 @@ "Name: debian\n" \ "Address: 127.0.0.1\n" +#define pidof_trivial_usage \ + "process-name [process-name ...]" +#define pidof_full_usage \ + "Lists the PIDs of all processes with names that match the names on the command line" +#define pidof_example_usage \ + "$ pidof init\n" \ + "1\n" + #ifndef BB_FEATURE_FANCY_PING #define ping_trivial_usage "host" #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 @@ #ifdef BB_NSLOOKUP APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN) #endif +#ifdef BB_PIDOF + APPLET(pidof, pidof_main, _BB_DIR_BIN) +#endif #ifdef BB_PING APPLET(ping, ping_main, _BB_DIR_BIN) #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 @@ "Name: debian\n" \ "Address: 127.0.0.1\n" +#define pidof_trivial_usage \ + "process-name [process-name ...]" +#define pidof_full_usage \ + "Lists the PIDs of all processes with names that match the names on the command line" +#define pidof_example_usage \ + "$ pidof init\n" \ + "1\n" + #ifndef BB_FEATURE_FANCY_PING #define ping_trivial_usage "host" #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 @@ +/* vi: set sw=4 ts=4: */ +/* + * pidof implementation for busybox + * + * Copyright (C) 2001 by Lineo, inc. + * Written by Erik Andersen , + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "busybox.h" + + +extern int pidof_main(int argc, char **argv) +{ + int opt; + + + /* do normal option parsing */ + while ((opt = getopt(argc, argv, "ne:f:")) > 0) { + switch (opt) { +#if 0 + case 'g': + break; + case 'e': + break; +#endif + default: + show_usage(); + } + } + + /* if we didn't get a process name, then we need to choke and die here */ + if (argv[optind] == NULL) + show_usage(); + + /* Looks like everything is set to go. */ + while(optind < argc) { + pid_t* pidList; + + pidList = find_pid_by_name( argv[optind]); + if (!pidList || *pidList<=0) { + break; + } + + for(; pidList && *pidList!=0; pidList++) { + printf("%ld ", (long)*pidList); + } + /* Note that we don't bother to free the memory + * allocated in find_pid_by_name(). It will be freed + * upon exit, so we can save a byte or two */ + optind++; + } + printf("\n"); + + return EXIT_SUCCESS; +} 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 @@ +/* vi: set sw=4 ts=4: */ +/* + * pidof implementation for busybox + * + * Copyright (C) 2001 by Lineo, inc. + * Written by Erik Andersen , + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "busybox.h" + + +extern int pidof_main(int argc, char **argv) +{ + int opt; + + + /* do normal option parsing */ + while ((opt = getopt(argc, argv, "ne:f:")) > 0) { + switch (opt) { +#if 0 + case 'g': + break; + case 'e': + break; +#endif + default: + show_usage(); + } + } + + /* if we didn't get a process name, then we need to choke and die here */ + if (argv[optind] == NULL) + show_usage(); + + /* Looks like everything is set to go. */ + while(optind < argc) { + pid_t* pidList; + + pidList = find_pid_by_name( argv[optind]); + if (!pidList || *pidList<=0) { + break; + } + + for(; pidList && *pidList!=0; pidList++) { + printf("%ld ", (long)*pidList); + } + /* Note that we don't bother to free the memory + * allocated in find_pid_by_name(). It will be freed + * upon exit, so we can save a byte or two */ + optind++; + } + printf("\n"); + + return EXIT_SUCCESS; +} diff --git a/usage.h b/usage.h index 2a2042292..08da42b27 100644 --- a/usage.h +++ b/usage.h @@ -1190,6 +1190,14 @@ "Name: debian\n" \ "Address: 127.0.0.1\n" +#define pidof_trivial_usage \ + "process-name [process-name ...]" +#define pidof_full_usage \ + "Lists the PIDs of all processes with names that match the names on the command line" +#define pidof_example_usage \ + "$ pidof init\n" \ + "1\n" + #ifndef BB_FEATURE_FANCY_PING #define ping_trivial_usage "host" #define ping_full_usage "Send ICMP ECHO_REQUEST packets to network hosts" -- 2.25.1