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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
474
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * pidof.c - Print the PIDs of all processes with the given names.
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2012 Andreas Heck <aheck@gmx.de>
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 * Not in SUSv4.
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
10
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config PIDOF
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "pidof"
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 default y
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 help
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 usage: pidof [NAME]...
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
16
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 Print the PIDs of all processes with the given names.
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 */
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 }
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
26
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 void pidof_main(void)
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
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
d76583999029 Add pidof by Andreas Heck.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 }