I just wrote up a simple pidof applet, closing bug #1197
authorEric Andersen <andersen@codepoet.org>
Tue, 31 Jul 2001 19:06:07 +0000 (19:06 -0000)
committerEric Andersen <andersen@codepoet.org>
Tue, 31 Jul 2001 19:06:07 +0000 (19:06 -0000)
 -Erik

Changelog
Config.h
applets.h
applets/usage.h
include/applets.h
include/usage.h
pidof.c [new file with mode: 0644]
procps/pidof.c [new file with mode: 0644]
usage.h

index 165736f5f80a9e536b70d369b23846674771b7e6..efd593ad601dc45149b637fc157f5b5818693e51 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -13,6 +13,7 @@
     New Applets:
        * David McCullough <davidm@lineo.com> -- modprobe
        * Vladimir Oleynik -- traceroute
+       * Erik Andersen -- pidof
 
     New Scripts:
        * David Schleef, Erik Andersen, Stuart Hughes -- depmod.pl
index f753401ded8708b6cc949e74dc5e096efa662ed3..4523fbcab3061303da770b1b81c08b2fd04c47e5 100644 (file)
--- 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
index 9fc59cda53c8b8c2463dcb6a3c3e990b418016cd..0786c39eb987303d662c65233ed3f3bff28cb94b 100644 (file)
--- a/applets.h
+++ b/applets.h
 #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
index 2a2042292bb3a01afa3289fe26c15d8a06c23a67..08da42b27b8ae53993fbff04428c144a972ef7c8 100644 (file)
        "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"
index 9fc59cda53c8b8c2463dcb6a3c3e990b418016cd..0786c39eb987303d662c65233ed3f3bff28cb94b 100644 (file)
 #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
index 2a2042292bb3a01afa3289fe26c15d8a06c23a67..08da42b27b8ae53993fbff04428c144a972ef7c8 100644 (file)
        "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 (file)
index 0000000..50dffd3
--- /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 <andersen@lineo.com>, <andersee@debian.org>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+#include <ctype.h>
+#include <string.h>
+#include <unistd.h>
+#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 (file)
index 0000000..50dffd3
--- /dev/null
@@ -0,0 +1,79 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * pidof implementation for busybox
+ *
+ * Copyright (C) 2001 by Lineo, inc.
+ * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+#include <ctype.h>
+#include <string.h>
+#include <unistd.h>
+#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 2a2042292bb3a01afa3289fe26c15d8a06c23a67..08da42b27b8ae53993fbff04428c144a972ef7c8 100644 (file)
--- a/usage.h
+++ b/usage.h
        "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"