374
|
1 /* vi: set sw=4 ts=4:
|
|
2 *
|
|
3 * nice.c - Run a program at a different niceness level.
|
|
4 *
|
|
5 * Copyright 2010 Rob Landley <rob@landley.net>
|
|
6 *
|
|
7 * See http://www.opengroup.org/onlinepubs/9699919799/utilities/nice.html
|
|
8
|
|
9 USE_NICE(NEWTOY(nice, "^<1n#", TOYFLAG_USR|TOYFLAG_BIN))
|
|
10
|
|
11 config NICE
|
|
12 bool "nice"
|
|
13 default y
|
|
14 help
|
|
15 usage: nice [-n PRIORITY] command [args...]
|
|
16
|
|
17 Run a command line at an increased or decreased scheduling priority.
|
|
18
|
|
19 Higher numbers make a program yield more CPU time, from 20 (lowest
|
|
20 priority) to -19 (highest). By default processes inherit their parent's
|
|
21 niceness (usually 0). By default this command adds 10 to the parent's
|
|
22 priority. Only root can set a negative niceness level.
|
|
23 */
|
|
24
|
|
25 #include "toys.h"
|
|
26
|
|
27 // Hello doesn't use these globals, they're here for example/skeleton purposes.
|
|
28
|
|
29 DEFINE_GLOBALS(
|
|
30 long priority;
|
|
31 )
|
|
32
|
|
33 #define TT this.nice
|
|
34
|
|
35 void nice_main(void)
|
|
36 {
|
|
37 if (!toys.optflags) TT.priority = 10;
|
|
38
|
|
39 nice(TT.priority);
|
|
40 if (getpriority(PRIO_PROCESS, getpid()) != TT.priority)
|
|
41 perror_exit("Can't set priority");
|
|
42
|
|
43 xexec(toys.optargs);
|
|
44 }
|