Mercurial > hg > toybox
annotate toys/nice.c @ 649:2364ace48ab1
Bugfix from Avery Pennarun: getpriority() uses a different range than nice(), so follow thenice man page and zero errno then check it if nice returns -1.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 16 Aug 2012 22:24:30 -0500 |
parents | b51faa4fe8e6 |
children |
rev | line source |
---|---|
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 | |
446
b51faa4fe8e6
Correct description of nice levels in help of nice
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
444
diff
changeset
|
19 Higher numbers make a program yield more CPU time, from -20 (highest |
b51faa4fe8e6
Correct description of nice levels in help of nice
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
444
diff
changeset
|
20 priority) to 19 (lowest). By default processes inherit their parent's |
374 | 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 | |
649
2364ace48ab1
Bugfix from Avery Pennarun: getpriority() uses a different range than nice(), so follow thenice man page and zero errno then check it if nice returns -1.
Rob Landley <rob@landley.net>
parents:
446
diff
changeset
|
37 errno = 0; |
2364ace48ab1
Bugfix from Avery Pennarun: getpriority() uses a different range than nice(), so follow thenice man page and zero errno then check it if nice returns -1.
Rob Landley <rob@landley.net>
parents:
446
diff
changeset
|
38 if (nice(TT.priority)==-1 && errno) perror_exit("Can't set priority"); |
374 | 39 |
40 xexec(toys.optargs); | |
41 } |