1 /* pidof.c - Print the Process IDs of all processes with the given names. 2 * 3 * Copyright 2012 Andreas Heck <aheck (at) gmx.de> 4 * Copyright 2012 Elie De Brauwer <eliedebrauwer (at) gmail.com> 5 * 6 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/pidof.html 7 8 USE_PIDOF(NEWTOY(pidof, "<1so:", TOYFLAG_BIN)) 9 10 config PIDOF 11 bool "pidof" 12 default y 13 help 14 usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]... 15 16 Print the PIDs of all processes with the given names. 17 18 -s single shot, only return one pid. 19 -o omit PID(s) 20 */ 21 22 #define FOR_pidof 23 #include "toys.h" 24 25 GLOBALS( 26 char *omit; 27 ) 28 29 static int print_pid(pid_t pid, char *name) 30 { 31 sprintf(toybuf, "%d", (int)pid); 32 if (comma_scan(TT.omit, toybuf, 0)) return 0; 33 xprintf(" %s"+!!toys.exitval, toybuf); 34 toys.exitval = 0; 35 36 return toys.optflags & FLAG_s; 37 } 38 39 void pidof_main(void) 40 { 41 toys.exitval = 1; 42 names_to_pid(toys.optargs, print_pid); 43 if (!toys.exitval) xputc('\n'); 44 } 45