From dschultz@HAL9000.wox.org  Sun Jan 20 00:03:05 2002
Return-Path: <dschultz@HAL9000.wox.org>
Received: from HAL9000.wox.org (12-232-222-90.client.attbi.com [12.232.222.90])
	by hub.freebsd.org (Postfix) with ESMTP id 8D34137B416
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 20 Jan 2002 00:03:04 -0800 (PST)
Received: (from dschultz@localhost)
	by HAL9000.wox.org (8.11.3/8.11.3) id g0K84wp01924;
	Sun, 20 Jan 2002 00:04:58 -0800 (PST)
	(envelope-from dschultz)
Message-Id: <200201200804.g0K84wp01924@HAL9000.wox.org>
Date: Sun, 20 Jan 2002 00:04:58 -0800 (PST)
From: dschultz@uclink.Berkeley.EDU
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] Add -n flag to renice; update docs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         34076
>Category:       bin
>Synopsis:       [PATCH] Add -n flag to renice; update docs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    maxim
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jan 20 00:10:01 PST 2002
>Closed-Date:    Mon Jun 17 17:09:57 PDT 2002
>Last-Modified:  Mon Jun 17 17:09:57 PDT 2002
>Originator:     David Schultz
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
cluttered
>Environment:
System: FreeBSD HAL9000.wox.org 4.3-RELEASE FreeBSD 4.3-RELEASE #6: Sun Jan 13 02:46:53 PST 2002 dschultz@HAL9000.wox.org:/usr/obj/usr/src/sys/HAL9000 i386
	

>Description:
Add the -n flag to renice, which allows priorities to be specified
as an offset of a process' current priority.
>How-To-Repeat:
>Fix:
--- renice.c.orig	Sat Jan 19 22:37:21 2002
+++ renice.c	Sat Jan 19 22:51:56 2002
@@ -56,7 +56,10 @@
 #include <string.h>
 #include <pwd.h>
 
-int donice __P((int, int, int));
+#define CHANGE_ABS 1
+#define CHANGE_REL 2
+
+int donice __P((int, int, int, int));
 static void usage __P((void));
 
 /*
@@ -70,17 +73,19 @@
 	char **argv;
 {
 	int which = PRIO_PROCESS;
-	int who = 0, prio, errs = 0;
+	int who = 0, prio, errs = 0, change = CHANGE_ABS;
 
 	argc--, argv++;
 	if (argc < 2)
 		usage();
+	if (strcmp(*argv, "-n") == 0) {
+		change = CHANGE_REL;
+		argc--, argv++;
+		if (argc < 2)
+			usage();
+	}
 	prio = atoi(*argv);
 	argc--, argv++;
-	if (prio > PRIO_MAX)
-		prio = PRIO_MAX;
-	if (prio < PRIO_MIN)
-		prio = PRIO_MIN;
 	for (; argc > 0; argc--, argv++) {
 		if (strcmp(*argv, "-g") == 0) {
 			which = PRIO_PGRP;
@@ -109,7 +114,7 @@
 				continue;
 			}
 		}
-		errs += donice(which, who, prio);
+		errs += donice(which, who, prio, change);
 	}
 	exit(errs != 0);
 }
@@ -118,13 +123,13 @@
 usage()
 {
 	fprintf(stderr,
-"usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\n");
+"usage: renice [ -n ] priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\n");
 	exit(1);
 }
 
 int
-donice(which, who, prio)
-	int which, who, prio;
+donice(which, who, prio, change)
+	int which, who, prio, change;
 {
 	int oldprio;
 
@@ -133,6 +138,12 @@
 		warn("%d: getpriority", who);
 		return (1);
 	}
+	if (change == CHANGE_REL)
+		prio += oldprio;
+	if (prio > PRIO_MAX)
+		prio = PRIO_MAX;
+	if (prio < PRIO_MIN)
+		prio = PRIO_MIN;
 	if (setpriority(which, who, prio) < 0) {
 		warn("%d: setpriority", who);
 		return (1);


--- renice.8.orig	Sat Jan 19 22:37:29 2002
+++ renice.8	Sat Jan 19 23:30:39 2002
@@ -40,6 +40,7 @@
 .Nd alter priority of running processes
 .Sh SYNOPSIS
 .Nm
+.Op Fl n
 .Ar priority
 .Oo
 .Op Fl p
@@ -73,6 +74,10 @@
 Options supported by
 .Nm :
 .Bl -tag -width Ds
+.It Fl n
+Interpret the
+.Ar priority
+parameter as an offset from the process' current priority.
 .It Fl g
 Force
 .Ar who
@@ -87,14 +92,6 @@
 interpretation to be (the default) process ID's.
 .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''
@@ -114,6 +111,21 @@
 in the system wants to),
 0 (the ``base'' scheduling priority),
 anything negative (to make things go very fast).
+.Sh EXAMPLES
+.Pp
+.Bd -literal -offset indent
+renice +1 987 -u daemon root -p 32
+.Ed
+.Pp
+Change the priority of process ID's 987 and 32, and
+all processes owned by users daemon and root.
+.Pp
+.Bd -literal -offset indent
+renice -n -5 654
+.Ed
+.Pp
+Decrease the ``nice value'' of process ID 654 by 5,
+assuming you are a super-user.
 .Sh FILES
 .Bl -tag -width /etc/passwd -compact
 .It Pa /etc/passwd

>Release-Note:
>Audit-Trail:

From: David Schultz <dschultz@uclink.Berkeley.EDU>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/34076: [PATCH] Add -n flag to renice; update docs
Date: Mon, 25 Mar 2002 11:38:20 -0800

 Due to a recent commit, you'll have to remove the three instances of
 __P from the diff to get this to apply cleanly against -CURRENT.
 It would be nice(1) if someone committed this or otherwise added a
 similar feature so I have two fewer trivial diffs to maintain.
State-Changed-From-To: open->patched 
State-Changed-By: maxim 
State-Changed-When: Wed Apr 10 04:18:40 PDT 2002 
State-Changed-Why:  
A similar diff were committed to -current. Thanks! 


Responsible-Changed-From-To: freebsd-bugs->maxim 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Wed Apr 10 04:18:40 PDT 2002 
Responsible-Changed-Why:  
I will MFC the fix in one week. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=34076 
State-Changed-From-To: patched->closed 
State-Changed-By: tjr 
State-Changed-When: Mon Jun 17 17:07:49 PDT 2002 
State-Changed-Why:  
Change has been MFC'd. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=34076 
>Unformatted:
