10f66f451Sopenharmony_ci/* nice.c - Run a program at a different niceness level.
20f66f451Sopenharmony_ci *
30f66f451Sopenharmony_ci * Copyright 2010 Rob Landley <rob@landley.net>
40f66f451Sopenharmony_ci *
50f66f451Sopenharmony_ci * See http://opengroup.org/onlinepubs/9699919799/utilities/nice.html
60f66f451Sopenharmony_ci
70f66f451Sopenharmony_ciUSE_NICE(NEWTOY(nice, "^<1n#", TOYFLAG_BIN))
80f66f451Sopenharmony_ci
90f66f451Sopenharmony_ciconfig NICE
100f66f451Sopenharmony_ci  bool "nice"
110f66f451Sopenharmony_ci  default y
120f66f451Sopenharmony_ci  help
130f66f451Sopenharmony_ci    usage: nice [-n PRIORITY] COMMAND...
140f66f451Sopenharmony_ci
150f66f451Sopenharmony_ci    Run a command line at an increased or decreased scheduling priority.
160f66f451Sopenharmony_ci
170f66f451Sopenharmony_ci    Higher numbers make a program yield more CPU time, from -20 (highest
180f66f451Sopenharmony_ci    priority) to 19 (lowest).  By default processes inherit their parent's
190f66f451Sopenharmony_ci    niceness (usually 0).  By default this command adds 10 to the parent's
200f66f451Sopenharmony_ci    priority.  Only root can set a negative niceness level.
210f66f451Sopenharmony_ci*/
220f66f451Sopenharmony_ci
230f66f451Sopenharmony_ci#define FOR_nice
240f66f451Sopenharmony_ci#include "toys.h"
250f66f451Sopenharmony_ci
260f66f451Sopenharmony_ciGLOBALS(
270f66f451Sopenharmony_ci  long n;
280f66f451Sopenharmony_ci)
290f66f451Sopenharmony_ci
300f66f451Sopenharmony_civoid nice_main(void)
310f66f451Sopenharmony_ci{
320f66f451Sopenharmony_ci  if (!toys.optflags) TT.n = 10;
330f66f451Sopenharmony_ci
340f66f451Sopenharmony_ci  errno = 0;
350f66f451Sopenharmony_ci  if (nice(TT.n)==-1 && errno) {
360f66f451Sopenharmony_ci    toys.exitval = 125;
370f66f451Sopenharmony_ci    perror_exit("Can't set priority");
380f66f451Sopenharmony_ci  }
390f66f451Sopenharmony_ci  xexec(toys.optargs);
400f66f451Sopenharmony_ci}
41