Date: Sun, 20 Jan 2002 00:04:58 -0800 (PST) From: dschultz@uclink.Berkeley.EDU To: FreeBSD-gnats-submit@freebsd.org Subject: bin/34076: [PATCH] Add -n flag to renice; update docs Message-ID: <200201200804.g0K84wp01924@HAL9000.wox.org>
next in thread | raw e-mail | index | archive | help
>Number: 34076 >Category: bin >Synopsis: [PATCH] Add -n flag to renice; update docs >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Jan 20 00:10:01 PST 2002 >Closed-Date: >Last-Modified: >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: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200201200804.g0K84wp01924>