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