annotate toys/posix/nice.c @ 840:8a6b36696ca6

Clean uudecode up the rest of the way, move pending->posix and default y.
author Rob Landley <rob@landley.net>
date Tue, 02 Apr 2013 01:34:34 -0500
parents 786841fdb1e0
children 144d5ba7d410
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
1 /* nice.c - Run a program at a different niceness level.
374
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 * Copyright 2010 Rob Landley <rob@landley.net>
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
656
6df4ccc0acbe Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/nice.html
374
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 USE_NICE(NEWTOY(nice, "^<1n#", TOYFLAG_USR|TOYFLAG_BIN))
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 config NICE
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
10 bool "nice"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
11 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
12 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
13 usage: nice [-n PRIORITY] command [args...]
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
14
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
15 Run a command line at an increased or decreased scheduling priority.
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
16
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
17 Higher numbers make a program yield more CPU time, from -20 (highest
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
18 priority) to 19 (lowest). By default processes inherit their parent's
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
19 niceness (usually 0). By default this command adds 10 to the parent's
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
20 priority. Only root can set a negative niceness level.
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
21 */
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
22
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
23 #define FOR_nice
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
24 #include "toys.h"
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
25
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
26 GLOBALS(
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
27 long priority;
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
28 )
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 void nice_main(void)
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
31 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
32 if (!toys.optflags) TT.priority = 10;
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
33
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
34 errno = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
35 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
36
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
37 xexec(toys.optargs);
374
633a5bf9509d Add command "nice".
Rob Landley <rob@landley.net>
parents:
diff changeset
38 }