Mercurial > hg > toybox
view toys/lsb/pidof.c @ 818:264b9da809df
Simplify license text, as mentioned on the mailing list.
Reasoning: it was never my intent to require anybody to copy license
text into another project if they cut and pasted something out of
toybox. The "permission for any purpose" is as close to public domain
as you can get in our current screwed up legal system without making
people uncomfortable the _other_ way. (Besides, my initial reading of
that was "all copies of the source code" but that's not what it says,
and somebody pointed out that Android has "show license text" options
because paranoid lawyers think that sort of thing applies to the BINARY
version, which is nuts.)
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 14 Mar 2013 09:02:37 -0500 |
parents | f169d9708518 |
children | 242c5de2bb22 |
line wrap: on
line source
/* 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:", TOYFLAG_USR|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 omits processes with specified PID */ #define FOR_pidof #include "toys.h" GLOBALS( char *omit; ) static int print_pid(pid_t pid, char * name) { char * res; int len; sprintf(toybuf, "%d", pid); len = strlen(toybuf); // Check omit string if (toys.optflags & FLAG_o) { res = strstr(TT.omit, toybuf); if (res && (res == TT.omit || res[-1] == ',') && (res[len] == ',' || res[len] == 0)) return 1; } xprintf("%*s", len+(!toys.exitval), toybuf); toys.exitval = 0; return !(toys.optflags & FLAG_s); } void pidof_main(void) { toys.exitval = 1; for_each_pid_with_name_in(toys.optargs, print_pid); if (!toys.exitval) xputc('\n'); }