# HG changeset patch # User Rob Landley # Date 1262777393 21600 # Node ID 633a5bf9509d310181474853a44246f471337760 # Parent 5e68c7cab1a4e06c34852cf022975bf03cbca79f Add command "nice". diff -r 5e68c7cab1a4 -r 633a5bf9509d toys/nice.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toys/nice.c Wed Jan 06 05:29:53 2010 -0600 @@ -0,0 +1,44 @@ +/* vi: set sw=4 ts=4: + * + * nice.c - Run a program at a different niceness level. + * + * Copyright 2010 Rob Landley + * + * 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); +}