summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog1
-rw-r--r--Config.h1
-rw-r--r--applets.h3
-rw-r--r--applets/usage.h8
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h8
-rw-r--r--pidof.c79
-rw-r--r--procps/pidof.c79
-rw-r--r--usage.h8
9 files changed, 190 insertions, 0 deletions
diff --git a/Changelog b/Changelog
index 165736f..efd593a 100644
--- 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
diff --git a/Config.h b/Config.h
index f753401..4523fbc 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 9fc59cd..0786c39 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 2a20422..08da42b 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 9fc59cd..0786c39 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 2a20422..08da42b 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 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
index 0000000..50dffd3
--- /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 <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 2a20422..08da42b 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"