comparison toys/pending/renice.c @ 977:9a96527bea94

Add renice.
author M. Farkas-Dyck <strake888@gmail.com>
date Mon, 29 Jul 2013 21:16:55 -0500
parents
children 6d3c39cb8a9d
comparison
equal deleted inserted replaced
976:f84dd3473233 977:9a96527bea94
1 /* renice.c - renice process
2 *
3 * Copyright 2013 CE Strake <strake888 at gmail.com>
4 *
5 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/
6 * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html
7
8 USE_RENICE(NEWTOY(renice, "gpun#", TOYFLAG_BIN))
9
10 config RENICE
11 bool "renice"
12 default n
13 help
14 usage: renice [-gpu] -n increment ID ...
15 */
16
17 #define FOR_renice
18 #include "toys.h"
19
20 GLOBALS(
21 long nArgu;
22 )
23
24 void renice_main (void) {
25 int ii;
26 int which = toys.optflags & FLAG_g ? PRIO_PGRP :
27 toys.optflags & FLAG_u ? PRIO_USER :
28 PRIO_PROCESS;
29
30 if (!(toys.optflags & FLAG_n)) error_exit ("no increment given");
31
32 for (ii = 0; ii < toys.optc; ii++) {
33 id_t id;
34
35 if (isdigit (toys.optargs[ii][0])) id = strtoul (toys.optargs[ii], 0, 10);
36 else if (toys.optflags & FLAG_u) id = getpwnam (toys.optargs[ii]) -> pw_uid;
37 else {
38 error_msg ("not a number: %s", toys.optargs[ii]);
39 toys.exitval = 1;
40 continue;
41 }
42
43 if (setpriority (which, id, getpriority (which, id) + TT.nArgu) < 0) {
44 error_msg ("failed to setpriority of %d", id);
45 toys.exitval = 1;
46 }
47 }
48 }