view 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
line wrap: on
line source

/* 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 (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.
*/

#include "toys.h"

DEFINE_GLOBALS(
	long priority;
)

#define TT this.nice

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(toys.optargs);
}