annotate toys/posix/nice.c @ 653:2986aa63a021

Move commands into "posix", "lsb", and "other" menus/directories.
author Rob Landley <rob@landley.net>
date Sat, 25 Aug 2012 14:25:22 -0500
parents toys/nice.c@2364ace48ab1
children 6df4ccc0acbe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * nice.c - Run a program at a different niceness level.
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright 2010 Rob Landley <rob@landley.net>
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
7 * See http://www.opengroup.org/onlinepubs/9699919799/utilities/nice.html
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
8
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
9 USE_NICE(NEWTOY(nice, "^<1n#", TOYFLAG_USR|TOYFLAG_BIN))
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
10
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
11 config NICE
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
12 bool "nice"
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
13 default y
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
14 help
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
15 usage: nice [-n PRIORITY] command [args...]
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
16
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
17 Run a command line at an increased or decreased scheduling priority.
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
18
446
b51faa4fe8e6 Correct description of nice levels in help of nice
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 444
diff changeset
19 Higher numbers make a program yield more CPU time, from -20 (highest
b51faa4fe8e6 Correct description of nice levels in help of nice
Elie De Brauwer <eliedebrauwer@gmail.com>
parents: 444
diff changeset
20 priority) to 19 (lowest). By default processes inherit their parent's
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
21 niceness (usually 0). By default this command adds 10 to the parent's
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
22 priority. Only root can set a negative niceness level.
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
23 */
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
24
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
25 #include "toys.h"
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
26
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
27 DEFINE_GLOBALS(
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
28 long priority;
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
29 )
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
30
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
31 #define TT this.nice
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
32
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
33 void nice_main(void)
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
34 {
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
35 if (!toys.optflags) TT.priority = 10;
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
36
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.
Rob Landley <rob@landley.net>
parents: 446
diff changeset
37 errno = 0;
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.
Rob Landley <rob@landley.net>
parents: 446
diff changeset
38 if (nice(TT.priority)==-1 && errno) perror_exit("Can't set priority");
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
39
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
40 xexec(toys.optargs);
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
41 }