view toys/posix/nice.c @ 1189:95ae2805622f draft

Add Szabolcs Nagy's deflate/inflate code from git://git.suckless.org/flate Confirmed with him on IRC it's ok to use under toybox license, glued the files together and hammered square peg into round hole, no other changes yet.
author Rob Landley <rob@landley.net>
date Fri, 31 Jan 2014 06:01:30 -0600
parents 144d5ba7d410
children cbb1aca81eca
line wrap: on
line source

/* nice.c - Run a program at a different niceness level.
 *
 * Copyright 2010 Rob Landley <rob@landley.net>
 *
 * See http://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 (highest
    priority) to 19 (lowest).  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.
*/

#define FOR_nice
#include "toys.h"

GLOBALS(
  long priority;
)

void nice_main(void)
{
  if (!toys.optflags) TT.priority = 10;

  errno = 0;
  if (nice(TT.priority)==-1 && errno) perror_exit("Can't set priority");

  xexec_optargs(0);
}