diff options
author | Rob Landley <rob@landley.net> | 2010-01-06 05:29:53 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2010-01-06 05:29:53 -0600 |
commit | 905060ab99df690356303f37387d95e788fa7d30 (patch) | |
tree | 0e7a1c092f7a1375ccc25a750409c87e4b8dbd32 | |
parent | db037ef6e0d7e84e5fd9ba831b55550a9b487257 (diff) | |
download | toybox-905060ab99df690356303f37387d95e788fa7d30.tar.gz |
Add command "nice".
-rw-r--r-- | toys/nice.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/toys/nice.c b/toys/nice.c new file mode 100644 index 00000000..2fda2675 --- /dev/null +++ b/toys/nice.c @@ -0,0 +1,44 @@ +/* vi: set sw=4 ts=4: + * + * nice.c - Run a program at a different niceness level. + * + * Copyright 2010 Rob Landley <rob@landley.net> + * + * See http://www.opengroup.org/onlinepubs/9699919799/utilities/nice.html + +USE_NICE(NEWTOY(nice, "^<1n#", TOYFLAG_USR|TOYFLAG_BIN)) + +config NICE + bool "nice" + default y + help + usage: nice [-n PRIORITY] command [args...] + + Run a command line at an increased or decreased scheduling priority. + + Higher numbers make a program yield more CPU time, from 20 (lowest + priority) to -19 (highest). By default processes inherit their parent's + niceness (usually 0). By default this command adds 10 to the parent's + priority. Only root can set a negative niceness level. +*/ + +#include "toys.h" + +// Hello doesn't use these globals, they're here for example/skeleton purposes. + +DEFINE_GLOBALS( + long priority; +) + +#define TT this.nice + +void nice_main(void) +{ + if (!toys.optflags) TT.priority = 10; + + nice(TT.priority); + if (getpriority(PRIO_PROCESS, getpid()) != TT.priority) + perror_exit("Can't set priority"); + + xexec(toys.optargs); +} |