OSDN Git Service

Simplify/unify listfiles recursion: populate directory node (and detect top of tree...
[android-x86/external-toybox.git] / toys / nice.c
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 (highest
20           priority) to 19 (lowest).  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 DEFINE_GLOBALS(
28         long priority;
29 )
30
31 #define TT this.nice
32
33 void nice_main(void)
34 {
35         if (!toys.optflags) TT.priority = 10;
36
37         nice(TT.priority);
38         if (getpriority(PRIO_PROCESS, getpid()) != TT.priority)
39                 perror_exit("Can't set priority");
40
41         xexec(toys.optargs);
42 }