Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Mar 2002 01:50:03 -0800
From:      Peter Avalos <pavalos@theshell.com>
To:        mike@freebsd.org
Cc:        freebsd-standards@freebsd.org
Subject:   renice(8)
Message-ID:  <20020307095003.GA11192@theshell.com>

next in thread | raw e-mail | index | archive | help

--WIyZ46R2i8wDzkSu
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Please review the following patch to make renice(8)
IEEE Std 1003.1-2001 compliant.  This may also be accessed at
http://www.theshell.com/~pavalos/renice.diff

o Accept the -n option.

o Make usage() and SYNOPSIS style(9) compliant.

o Accept only one -g, -p, or -u option, and clarify how they affect
  the interpretation of the following IDs.

o Update the EXAMPLES section to match this new behavior.

o Note that it is IEEE Std 1003.1-2001 compliant, but we still accept
  a nice value for POLA.

o Use __FBSDID.

o Remove __P() usage.

o Use static for local functions.

o Change K&R declarations.

o Remove register.

o int main(int argc, char *argv[])

o style(9) variable declaration.

o Allow user to specify both user names and user ids.

o Use sysexits when appropriate.


--Pete


Index: renice.8
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/fbsd/src/usr.bin/renice/renice.8,v
retrieving revision 1.9
diff -u -r1.9 renice.8
--- renice.8	5 Aug 2001 22:07:27 -0000	1.9
+++ renice.8	7 Mar 2002 09:26:45 -0000
@@ -40,90 +40,103 @@
 .Nd alter priority of running processes
 .Sh SYNOPSIS
 .Nm
-.Ar priority
+.Ar nice_value
 .Oo
-.Op Fl p
-.Ar pid ...
+.Fl g |
+.Fl p
+|
+.Fl u
 .Oc
+.Ar ID ...
+.Nm
+.Fl n Ar increment
 .Oo
-.Op Fl g
-.Ar pgrp ...
-.Oc
-.Oo
-.Op Fl u
-.Ar user ...
+.Fl g |
+.Fl p
+|
+.Fl u
 .Oc
+.Ar ID ...
 .Sh DESCRIPTION
 .Nm Renice
 alters the
 scheduling priority of one or more running processes.
-The following
-.Ar who
-parameters are interpreted as process ID's, process group
-ID's, or user names.
-.Nm Renice Ns 'ing
+By default, the processes to be affected are specified by
+their process ID's.
+Specifying
 a process group causes all processes in the process group
 to have their scheduling priority altered.
-.Nm Renice Ns 'ing
+Specifying
 a user causes all processes owned by the user to have
 their scheduling priority altered.
-By default, the processes to be affected are specified by
-their process ID's.
+.Pp
+If the requested priority or increment would exceed PRIO_MIN (\-20)
+or PRIO_MAX (20), the limit that was exceeded is used.
+Only the superuser may affect the scheduling priority of processes
+owned by another user.
+Only the superuser may increase the scheduling priority of a process
+(decrease the nice_value).
 .Pp
 Options supported by
 .Nm :
 .Bl -tag -width Ds
+.It Fl n Ar increment
+Increment the scheduling priority of the specified process.
+Positive values will decrease the scheduling priority, and negative
+values will increase the scheduling priority.
+Only the superuser may specify a negative value.
 .It Fl g
-Force
-.Ar who
-parameters to be interpreted as process group ID's.
-.It Fl u
-Force the
-.Ar who
-parameters to be interpreted as user names.
+Interpret all
+.Ar ID
+arguments as unsigned decimal integer process group ID's.
 .It Fl p
-Resets the
-.Ar who
-interpretation to be (the default) process ID's.
+Interpret all
+.Ar ID
+arguments as unsigned decimal integer process ID's.
+This is the default if no options are specified.
+.It Fl u
+Interpret all
+.Ar ID
+arguments as users.
+The
+.Ar ID
+may be a valid user name or an unsigned decimal integer user ID.
 .El
 .Pp
-For example,
-.Bd -literal -offset
-renice +1 987 -u daemon root -p 32
-.Ed
-.Pp
-would change the priority of process ID's 987 and 32, and
-all processes owned by users daemon and root.
-.Pp
-Users other than the super-user may only alter the priority of
-processes they own,
-and can only monotonically increase their ``nice value''
-within the range 0 to
-.Dv PRIO_MAX
-(20).
-(This prevents overriding administrative fiats.)
-The super-user
-may alter the priority of any process
-and set the priority to any value in the range
-.Dv PRIO_MIN
-(\-20)
-to
-.Dv PRIO_MAX .
-Useful priorities are:
+Useful nice_values are:
 20 (the affected processes will run only when nothing else
 in the system wants to),
 0 (the ``base'' scheduling priority),
 anything negative (to make things go very fast).
-.Sh FILES
-.Bl -tag -width /etc/passwd -compact
-.It Pa /etc/passwd
-to map user names to user ID's
-.El
+.Sh EXAMPLES
+Adjust the system scheduling priority so group
+ID's 69 and 77 have a lower priority:
+.Pp
+.Dl % renice -n 5 -g 69 77
+.Pp
+Adjust the system scheduling priority so process
+ID's 2987 and 85723 have the lowest priority:
+.Pp
+.Dl % renice 20 2987 85723
+.Pp
+Adjust the system scheduling priority so user
+foo and user ID 2000 have higher priority:
+.Pp
+.Dl # renice -n -5 -u foo 2000
+.Pp
 .Sh SEE ALSO
 .Xr nice 1 ,
 .Xr rtprio 1 ,
 .Xr getpriority 2 ,
 .Xr setpriority 2
+.Sh STANDARDS
+The
+.Nm
+utility conforms to
+.St -p1003.1-2001
+Note: Specifying
+.Ar nice_value
+is deprecated, but it is accepted due to its historical significance.
 .Sh BUGS
 Non super-users cannot increase scheduling priorities of their own process=
es,
 even if they were the ones that decreased the priorities in the first plac=
e.
Index: renice.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/fbsd/src/usr.bin/renice/renice.c,v
retrieving revision 1.7
diff -u -r1.7 renice.c
--- renice.c	3 Dec 2001 21:18:12 -0000	1.7
+++ renice.c	7 Mar 2002 09:22:23 -0000
@@ -31,19 +31,20 @@
  * SUCH DAMAGE.
  */
=20
+#if 0
 #ifndef lint
-static const char copyright[] =3D
+static char copyright[] =3D
 "@(#) Copyright (c) 1983, 1989, 1993\n\
 	The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
=20
 #ifndef lint
-#if 0
 static char sccsid[] =3D "@(#)renice.c	8.1 (Berkeley) 6/9/93";
-#endif
-static const char rcsid[] =3D
-  "$FreeBSD: src/usr.bin/renice/renice.c,v 1.7 2001/12/03 21:18:12 dwmalon=
e Exp $";
 #endif /* not lint */
+#endif
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
=20
 #include <sys/types.h>
 #include <sys/time.h>
@@ -51,13 +52,15 @@
=20
 #include <err.h>
 #include <errno.h>
+#include <limits.h>
+#include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <pwd.h>
+#include <sysexits.h>
=20
-int donice __P((int, int, int));
-static void usage __P((void));
+static int donice(int, int, int, int);
+static void usage(void);
=20
 /*
  * Change the priority (nice) of processes
@@ -65,66 +68,79 @@
  * running.
  */
 int
-main(argc, argv)
-	int argc;
-	char **argv;
+main(int argc, char *argv[])
 {
-	int which =3D PRIO_PROCESS;
-	int who =3D 0, prio, errs =3D 0;
+	struct passwd *pwd;
+	char *endptr;
+	int errs, nflag, prio, which, who;
+
+	which =3D PRIO_PROCESS;
+	errs =3D 0, nflag =3D 0, who =3D 0;
=20
 	argc--, argv++;
 	if (argc < 2)
 		usage();
-	prio =3D atoi(*argv);
+
+	/* Parse priority or -n increment. */
+	if (strcmp(*argv, "-n") =3D=3D 0) {
+		nflag =3D 1;
+		argc--, argv++;
+		if (argc < 2)
+			usage();
+	}
+	prio =3D strtol(*argv, &endptr, 10);
+	if (*endptr ||
+	    ((prio =3D=3D LONG_MAX || prio =3D=3D LONG_MIN) && errno =3D=3D ERANG=
E))
+		errx(EX_DATAERR, "Invalid input: %s", *argv);
 	argc--, argv++;
-	if (prio > PRIO_MAX)
-		prio =3D PRIO_MAX;
-	if (prio < PRIO_MIN)
-		prio =3D PRIO_MIN;
+
+	/*
+	 * Accept -g, -p, -u, or a number. If it's a number, default
+	 * to -p (PRIO_PROCESS).
+	 */
+	if (strcmp(*argv, "-g") =3D=3D 0) {
+		which =3D PRIO_PGRP;
+		argc--, argv++;
+	} else if (strcmp(*argv, "-u") =3D=3D 0) {
+		which =3D PRIO_USER;
+		argc--, argv++;
+	} else if (strcmp(*argv, "-p") =3D=3D 0)
+		argc--, argv++;
+
 	for (; argc > 0; argc--, argv++) {
-		if (strcmp(*argv, "-g") =3D=3D 0) {
-			which =3D PRIO_PGRP;
-			continue;
-		}
-		if (strcmp(*argv, "-u") =3D=3D 0) {
-			which =3D PRIO_USER;
-			continue;
-		}
-		if (strcmp(*argv, "-p") =3D=3D 0) {
-			which =3D PRIO_PROCESS;
+		who =3D strtoul(*argv, &endptr, 10);
+
+		/* If argv is not a number, then we should be PRIO_USER. */
+		if ((*endptr && which !=3D PRIO_USER) ||
+		    ((who =3D=3D LONG_MAX || who =3D=3D LONG_MIN) && errno =3D=3D ERANGE=
)) {
+			warnx("Invalid input: %s", *argv);
 			continue;
 		}
-		if (which =3D=3D PRIO_USER) {
-			register struct passwd *pwd =3D getpwnam(*argv);
+		if (which =3D=3D PRIO_USER && *endptr) {
+			pwd =3D getpwnam(*argv);
=20
 			if (pwd =3D=3D NULL) {
 				warnx("%s: unknown user", *argv);
 				continue;
 			}
 			who =3D pwd->pw_uid;
-		} else {
-			who =3D atoi(*argv);
-			if (who < 0) {
-				warnx("%s: bad value", *argv);
-				continue;
-			}
 		}
-		errs +=3D donice(which, who, prio);
+		errs +=3D donice(which, who, prio, nflag);
 	}
-	exit(errs !=3D 0);
+	exit(errs);
 }
=20
 static void
-usage()
+usage(void)
 {
-	fprintf(stderr,
-"usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\=
n");
-	exit(1);
+
+	fprintf(stderr, "usage: renice nice_value [-g | -p | -u] ID ...\n");
+	fprintf(stderr, "       renice -n increment [-g | -p | -u] ID ...\n");
+	exit(EX_USAGE);
 }
=20
-int
-donice(which, who, prio)
-	int which, who, prio;
+static int
+donice(int which, int who, int prio, int nflag)
 {
 	int oldprio;
=20
@@ -133,10 +149,12 @@
 		warn("%d: getpriority", who);
 		return (1);
 	}
+	if (nflag)
+		prio +=3D oldprio; /* Possible over/underflow here. */
 	if (setpriority(which, who, prio) < 0) {
 		warn("%d: setpriority", who);
 		return (1);
 	}
-	printf("%d: old priority %d, new priority %d\n", who, oldprio, prio);
+	printf("%d: old nice_value %d, new nice_value %d\n", who, oldprio, prio);
 	return (0);
 }

--WIyZ46R2i8wDzkSu
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE8hzfK7ogfS9uZ4RsRAgkxAKDTOEX4bBdVzcSePKxbLtPzUyKvVwCg0Pgu
+cd+or3WjzsaV78osNcrRvM=
=0iPJ
-----END PGP SIGNATURE-----

--WIyZ46R2i8wDzkSu--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020307095003.GA11192>