Mercurial > hg > toybox
annotate toys/lsb/pidof.c @ 832:75526930cdd7
Add help text for pending test command. (No actual implementation yet.)
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 26 Mar 2013 22:31:10 -0500 |
parents | f169d9708518 |
children | 242c5de2bb22 |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
1 /* pidof.c - Print the Process IDs of all processes with the given names. |
474 | 2 * |
3 * Copyright 2012 Andreas Heck <aheck@gmx.de> | |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
4 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com> |
474 | 5 * |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
6 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/pidof.html |
474 | 7 |
745 | 8 USE_PIDOF(NEWTOY(pidof, "<1so:", TOYFLAG_USR|TOYFLAG_BIN)) |
474 | 9 |
10 config PIDOF | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
11 bool "pidof" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
12 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
13 help |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
14 usage: pidof [-s] [-o omitpid[,omitpid..]] [NAME]... |
474 | 15 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
16 Print the PIDs of all processes with the given names. |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
17 -s single shot, only return one pid. |
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
18 -o omits processes with specified PID |
474 | 19 */ |
20 | |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
21 #define FOR_pidof |
474 | 22 #include "toys.h" |
23 | |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
24 GLOBALS( |
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
25 char *omit; |
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
26 ) |
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
27 |
762
f169d9708518
Extend killall with support for -v and -i
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
745
diff
changeset
|
28 static int print_pid(pid_t pid, char * name) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
29 { |
745 | 30 char * res; |
31 int len; | |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
32 |
745 | 33 sprintf(toybuf, "%d", pid); |
34 len = strlen(toybuf); | |
35 | |
36 // Check omit string | |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
37 if (toys.optflags & FLAG_o) |
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
38 { |
745 | 39 res = strstr(TT.omit, toybuf); |
40 if (res && (res == TT.omit || res[-1] == ',') && | |
41 (res[len] == ',' || res[len] == 0)) return 1; | |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
42 } |
745 | 43 xprintf("%*s", len+(!toys.exitval), toybuf); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
44 toys.exitval = 0; |
744
43e6ec52aa29
Adding -s (single shot) and -o (omit pids) options to pidof
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
694
diff
changeset
|
45 |
745 | 46 return !(toys.optflags & FLAG_s); |
474 | 47 } |
48 | |
49 void pidof_main(void) | |
50 { | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
51 toys.exitval = 1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
52 for_each_pid_with_name_in(toys.optargs, print_pid); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
53 if (!toys.exitval) xputc('\n'); |
474 | 54 } |