comparison toys/posix/renice.c @ 979:53a9bcb938f0

Move renice from pending to posix, default y, fix link to standard.
author Rob Landley <rob@landley.net>
date Wed, 31 Jul 2013 16:36:57 -0500
parents toys/pending/renice.c@6d3c39cb8a9d
children 57f2a26fa92c
comparison
equal deleted inserted replaced
978:6d3c39cb8a9d 979:53a9bcb938f0
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/renice.html
6
7 USE_RENICE(NEWTOY(renice, "<1gpun#|", TOYFLAG_BIN))
8
9 config RENICE
10 bool "renice"
11 default y
12 help
13 usage: renice [-gpu] -n increment ID ...
14 */
15
16 #define FOR_renice
17 #include "toys.h"
18
19 GLOBALS(
20 long nArgu;
21 )
22
23 void renice_main(void) {
24 int which = (toys.optflags & FLAG_g) ? PRIO_PGRP :
25 ((toys.optflags & FLAG_u) ? PRIO_USER : PRIO_PROCESS);
26 char **arg;
27
28 for (arg = toys.optargs; *arg; arg++) {
29 char *s = *arg;
30 int id = -1;
31
32 if (toys.optflags & FLAG_u) {
33 struct passwd *p = getpwnam(s);
34 if (p) id = p->pw_uid;
35 } else {
36 id = strtol(s, &s, 10);
37 if (*s) id = -1;
38 }
39
40 if (id < 0) {
41 error_msg("bad '%s'", *arg);
42 continue;
43 }
44
45 if (setpriority(which, id, getpriority(which, id)+TT.nArgu) < 0)
46 perror_msg("setpriority %d", id);
47 }
48 }