You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1009 B
46 lines
1009 B
4 months ago
|
/* pidof.c - Print the Process IDs of all processes with the given names.
|
||
|
*
|
||
|
* Copyright 2012 Andreas Heck <aheck@gmx.de>
|
||
|
* Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
|
||
|
*
|
||
|
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/pidof.html
|
||
|
|
||
|
USE_PIDOF(NEWTOY(pidof, "<1so:x", TOYFLAG_BIN))
|
||
|
|
||
|
config PIDOF
|
||
|
bool "pidof"
|
||
|
default y
|
||
|
help
|
||
|
usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...
|
||
|
|
||
|
Print the PIDs of all processes with the given names.
|
||
|
|
||
|
-s Single shot, only return one pid
|
||
|
-o Omit PID(s)
|
||
|
-x Match shell scripts too
|
||
|
*/
|
||
|
|
||
|
#define FOR_pidof
|
||
|
#include "toys.h"
|
||
|
|
||
|
GLOBALS(
|
||
|
char *omit;
|
||
|
)
|
||
|
|
||
|
static int print_pid(pid_t pid, char *name)
|
||
|
{
|
||
|
sprintf(toybuf, "%d", (int)pid);
|
||
|
if (comma_scan(TT.omit, toybuf, 0)) return 0;
|
||
|
xprintf(" %s"+!!toys.exitval, toybuf);
|
||
|
toys.exitval = 0;
|
||
|
|
||
|
return toys.optflags & FLAG_s;
|
||
|
}
|
||
|
|
||
|
void pidof_main(void)
|
||
|
{
|
||
|
toys.exitval = 1;
|
||
|
names_to_pid(toys.optargs, print_pid, FLAG(x));
|
||
|
if (!toys.exitval) xputc('\n');
|
||
|
}
|