Created
December 29, 2010 11:31
-
-
Save thesjg/758440 to your computer and use it in GitHub Desktop.
renice -a patchset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- Makefile-old Sat Apr 26 00:33:36 2003 | |
| +++ Makefile Sat Apr 26 00:32:27 2003 | |
| @@ -3,5 +3,7 @@ | |
| PROG= renice | |
| MAN= renice.8 | |
| +DPADD= ${LIBKVM} | |
| +LDADD= -lkvm | |
| .include <bsd.prog.mk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- renice-old.8 Sat Apr 26 00:33:55 2003 | |
| +++ renice.8 Sat Apr 26 00:46:22 2003 | |
| @@ -40,13 +40,9 @@ | |
| .Nd alter priority of running processes | |
| .Sh SYNOPSIS | |
| .Nm | |
| -.Ar priority | |
| -.Op Oo Fl p Oc Ar pid ... | |
| -.Op Oo Fl g Oc Ar pgrp ... | |
| -.Op Oo Fl u Oc Ar user ... | |
| -.Nm | |
| -.Fl n Ar increment | |
| +.Fl n Ar increment | priority | |
| .Op Oo Fl p Oc Ar pid ... | |
| +.Op Oo Fl a Oc Ar pname ... | |
| .Op Oo Fl g Oc Ar pgrp ... | |
| .Op Oo Fl u Oc Ar user ... | |
| .Sh DESCRIPTION | |
| @@ -83,6 +79,10 @@ | |
| Force the | |
| .Ar who | |
| parameters to be interpreted as user names or user ID's. | |
| +.It Fl a | |
| +Force the | |
| +.Ar who | |
| +paramaters to be interpreted as process names. | |
| .It Fl p | |
| Reset the | |
| .Ar who |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- renice-old.c Fri Apr 25 22:43:31 2003 | |
| +++ renice.c Sat Apr 26 00:57:47 2003 | |
| @@ -46,13 +46,20 @@ | |
| #include <sys/cdefs.h> | |
| __FBSDID("$FreeBSD: src/usr.bin/renice/renice.c,v 1.17 2003/02/26 20:27:24 charnier Exp $"); | |
| +#include <sys/param.h> | |
| +#include <sys/sysctl.h> | |
| #include <sys/types.h> | |
| #include <sys/time.h> | |
| #include <sys/resource.h> | |
| +#include <sys/user.h> | |
| +#include <ctype.h> | |
| #include <err.h> | |
| #include <errno.h> | |
| +#include <fcntl.h> | |
| +#include <kvm.h> | |
| #include <limits.h> | |
| +#include <paths.h> | |
| #include <pwd.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| @@ -60,6 +67,7 @@ | |
| static int donice(int, int, int, int); | |
| static int getnum(const char *, const char *, int *); | |
| +static int doalpha(const char *, int, int); | |
| static void usage(void); | |
| /* | |
| @@ -71,12 +79,13 @@ | |
| main(int argc, char *argv[]) | |
| { | |
| struct passwd *pwd; | |
| - int errs, incr, prio, which, who; | |
| + int errs, incr, prio, which, who, alpha; | |
| errs = 0; | |
| incr = 0; | |
| which = PRIO_PROCESS; | |
| who = 0; | |
| + alpha = 0; | |
| argc--, argv++; | |
| if (argc < 2) | |
| usage(); | |
| @@ -92,14 +101,22 @@ | |
| for (; argc > 0; argc--, argv++) { | |
| if (strcmp(*argv, "-g") == 0) { | |
| which = PRIO_PGRP; | |
| + alpha = 0; | |
| continue; | |
| } | |
| if (strcmp(*argv, "-u") == 0) { | |
| which = PRIO_USER; | |
| + alpha = 0; | |
| continue; | |
| } | |
| if (strcmp(*argv, "-p") == 0) { | |
| which = PRIO_PROCESS; | |
| + alpha = 0; | |
| + continue; | |
| + } | |
| + if (strcmp(*argv, "-a") == 0) { | |
| + which = PRIO_PROCESS; | |
| + alpha = 1; | |
| continue; | |
| } | |
| if (which == PRIO_USER) { | |
| @@ -114,6 +131,10 @@ | |
| continue; | |
| } | |
| } else { | |
| + if (alpha && isalpha(**argv)) { | |
| + doalpha(*argv, which, prio); | |
| + continue; | |
| + } | |
| if (getnum("pid", *argv, &who)) { | |
| errs++; | |
| continue; | |
| @@ -176,11 +197,36 @@ | |
| return (0); | |
| } | |
| +static int | |
| +doalpha(const char *name, int which, int prio) | |
| +{ | |
| + kvm_t *kd; | |
| + struct kinfo_proc *kp; | |
| + register int i; | |
| + int pcount, errs; | |
| + char *errbuf; | |
| + | |
| + errs = 0; | |
| + kd = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, errbuf); | |
| + if (kd == NULL) | |
| + errx(1, "%s", errbuf); | |
| + | |
| + kp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &pcount); | |
| + if (kp == NULL) | |
| + errx(1, "%s", kvm_geterr(kd)); | |
| + | |
| + for (i = 0; i < pcount; ++i) | |
| + if (!strcmp(kp[i].ki_comm, name)) | |
| + errs += donice(which, kp[i].ki_pid, prio, 0); | |
| + | |
| + return (errs); | |
| +} | |
| + | |
| static void | |
| usage() | |
| { | |
| fprintf(stderr, "%s\n%s\n", | |
| -"usage: renice priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]", | |
| -" renice -n increment [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]"); | |
| +"usage: renice -n increment | priority [[-p] pid ...] [[-a] pname ...]", | |
| +"[[-g] pgrp ...] [[-u] user ...]"); | |
| exit(1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment