Mercurial > hg > toybox
annotate toys/pidof.c @ 562:4d802d438983
Match uint64_t with PRIu64 to avoid warnings on 64 bit builds.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 14 Apr 2012 21:27:00 -0500 |
parents | f0b07ce5f125 |
children |
rev | line source |
---|---|
474 | 1 /* vi: set sw=4 ts=4: |
2 * | |
3 * pidof.c - Print the PIDs of all processes with the given names. | |
4 * | |
5 * Copyright 2012 Andreas Heck <aheck@gmx.de> | |
6 * | |
7 * Not in SUSv4. | |
8 | |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
9 USE_PIDOF(NEWTOY(pidof, "<1", TOYFLAG_USR|TOYFLAG_BIN)) |
474 | 10 |
11 config PIDOF | |
12 bool "pidof" | |
13 default y | |
14 help | |
15 usage: pidof [NAME]... | |
16 | |
17 Print the PIDs of all processes with the given names. | |
18 */ | |
19 | |
20 #include "toys.h" | |
21 | |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
22 static void print_pid(pid_t pid) { |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
23 xprintf("%s%ld", toys.exitval ? "" : " ", (long)pid); |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
24 toys.exitval = 0; |
474 | 25 } |
26 | |
27 void pidof_main(void) | |
28 { | |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
29 toys.exitval = 1; |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
30 for_each_pid_with_name_in(toys.optargs, print_pid); |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
31 if (!toys.exitval) xputc('\n'); |
474 | 32 } |