Changed to be POSIX.2 compliant.
This commit is contained in:
parent
f3781892d9
commit
7b5c7989f0
@ -1,7 +1,6 @@
|
||||
.\" Copyright (c) 1980, 1990 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
@ -31,63 +30,83 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)nice.1 6.7 (Berkeley) 7/24/91
|
||||
.\" $Id: nice.1,v 1.2 1993/08/01 07:30:16 mycroft Exp $
|
||||
.\" $Id: nice.1,v 1.3 1993/08/27 20:22:04 jtc Exp $
|
||||
.\"
|
||||
.Dd July 24, 1991
|
||||
.Dt NICE 1
|
||||
.Os BSD 4
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm nice
|
||||
.Nd execute a Bourne shell command at a low scheduling priority
|
||||
.Nd execute a utility with an altered scheduling priority
|
||||
.Sh SYNOPSIS
|
||||
.Nm nice
|
||||
.Op Fl Ns Ar number
|
||||
.Ar command
|
||||
.Op Ar arguments
|
||||
.Op Fl n Ar increment
|
||||
.Ar utility
|
||||
.Op Ar argument ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm Nice
|
||||
runs
|
||||
.Ar command
|
||||
at a low priority.
|
||||
(Think of low and slow).
|
||||
If
|
||||
.Fl Ns Ar number
|
||||
is specified, and if it is greater than or equal
|
||||
to 10 (the default),
|
||||
.Nm nice
|
||||
will execute
|
||||
.Ar command
|
||||
at that priority.
|
||||
The upper bound, or lowest priority that
|
||||
.Nm nice
|
||||
will run a command is 20.
|
||||
The lower bounds or
|
||||
higher priorities (integers less than 10)
|
||||
can only be requested by the super-user.
|
||||
Negative numbers are expressed as
|
||||
.Fl - Ns Ar number .
|
||||
.Ar utility
|
||||
at an altered scheduling priority.
|
||||
If an
|
||||
.Ar increment
|
||||
is given, it is used; otherwise
|
||||
an increment of 10 is assumed.
|
||||
The super-user can run utilities with priorities higher than normal by using
|
||||
a negative
|
||||
.Ar increment .
|
||||
The priority can be adjusted over a
|
||||
range of -20 (the higest) to 20 (the lowest).
|
||||
.Pp
|
||||
The returned exit status is the exit value from the
|
||||
command executed by
|
||||
.Nm nice .
|
||||
Available options:
|
||||
.Bl -tag -width indent
|
||||
.It Fl n Ar increment
|
||||
A positive or negative decimal integer used to modify the system scheduling
|
||||
priority of
|
||||
.Ar utility.
|
||||
.El
|
||||
.Sh DIAGNOSTICS
|
||||
The
|
||||
.Nm nice
|
||||
utility shall exit with one of the following values:
|
||||
.Bl -tag -width indent
|
||||
.It 1-125
|
||||
An error occured in the
|
||||
.Nm nice
|
||||
utility.
|
||||
.It 126
|
||||
The
|
||||
.Ar utility
|
||||
was found but could not be invoked.
|
||||
.It 127
|
||||
The
|
||||
.Ar utility
|
||||
could not be found.
|
||||
.El
|
||||
.Pp
|
||||
Otherwise, the exit status of
|
||||
.Nm nice
|
||||
shall be that of
|
||||
.Ar utility .
|
||||
.Sh COMPATIBILITY
|
||||
The historic
|
||||
.Fl Ns Ar increment
|
||||
option has been deprecated but is still supported in this implementation.
|
||||
.Sh SEE ALSO
|
||||
.Xr csh 1 ,
|
||||
.Xr renice 8
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm nice
|
||||
utility conforms to
|
||||
.St -p1003.2-92 .
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm nice
|
||||
command appeared in
|
||||
utility appeared in
|
||||
.At v6 .
|
||||
.Sh BUGS
|
||||
.Nm Nice
|
||||
is particular to
|
||||
.Xr sh 1 .
|
||||
If you use
|
||||
.Xr csh 1 ,
|
||||
then commands executed with ``&'' are automatically immune to hangup
|
||||
signals while in the background.
|
||||
.Pp
|
||||
.Nm Nice
|
||||
is built into
|
||||
.Xr csh 1
|
||||
with a slightly different syntax than described here. The form
|
||||
|
@ -39,14 +39,17 @@ char copyright[] =
|
||||
|
||||
#ifndef lint
|
||||
/*static char sccsid[] = "from: @(#)nice.c 5.4 (Berkeley) 6/1/90";*/
|
||||
static char rcsid[] = "$Id: nice.c,v 1.3 1993/08/01 18:10:32 mycroft Exp $";
|
||||
static char rcsid[] = "$Id: nice.c,v 1.4 1993/08/27 20:22:06 jtc Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
#define DEFNICE 10
|
||||
|
||||
@ -55,48 +58,49 @@ main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
extern int errno;
|
||||
int niceness;
|
||||
int niceness = DEFNICE;
|
||||
int c;
|
||||
|
||||
if (!argv[1])
|
||||
usage();
|
||||
/* handle obsolete -number syntax */
|
||||
if (argc > 1 && argv[1][0] == '-' && isdigit(argv[1][1])) {
|
||||
niceness = atoi (argv[1] + 1);
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
niceness = DEFNICE;
|
||||
if (argv[1][0] == '-')
|
||||
if (isdigit(argv[1][1]) || argv[1][1] == '-') {
|
||||
niceness = atoi(argv[1] + 1);
|
||||
++argv;
|
||||
}
|
||||
else {
|
||||
(void)fprintf(stderr, "nice: illegal option -- %c\n",
|
||||
argv[1][1]);
|
||||
while ((c = getopt (argc, argv, "n:")) != -1) {
|
||||
switch (c) {
|
||||
case 'n':
|
||||
niceness = atoi (optarg);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
argc -= optind; argv += optind;
|
||||
|
||||
if (!argv[1])
|
||||
if (argc == 0)
|
||||
usage();
|
||||
|
||||
errno = 0;
|
||||
niceness += getpriority(PRIO_PROCESS, 0);
|
||||
if (errno) {
|
||||
(void)fprintf(stderr, "nice: getpriority: %s\n",
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
err (1, "getpriority");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if (setpriority(PRIO_PROCESS, 0, niceness)) {
|
||||
(void)fprintf(stderr, "nice: setpriority: %s\n",
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
warn ("setpriority");
|
||||
}
|
||||
execvp(argv[1], &argv[1]);
|
||||
(void)fprintf(stderr,
|
||||
"nice: %s: %s\n", argv[1], strerror(errno));
|
||||
exit(1);
|
||||
execvp(argv[0], &argv[0]);
|
||||
err ((errno == ENOENT) ? 127 : 126, argv[0]);
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"nice [ -# ] command [ options ] [ operands ]\n");
|
||||
"usage: nice [ -n increment ] utility [ argument ...]\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user