Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/pkill add a "prenice <priority> <names>" command.
details: https://anonhg.NetBSD.org/src/rev/81e239eca02b
branches: trunk
changeset: 759331:81e239eca02b
user: mrg <mrg%NetBSD.org@localhost>
date: Mon Dec 06 04:00:11 2010 +0000
description:
add a "prenice <priority> <names>" command.
use it like "prenice -4 mplayer".
diffstat:
usr.bin/pkill/pkill.1 | 25 +++++-
usr.bin/pkill/pkill.c | 185 +++++++++++++++++++++++++++++++------------------
2 files changed, 139 insertions(+), 71 deletions(-)
diffs (truncated from 309 to 300 lines):
diff -r b77fcd880d44 -r 81e239eca02b usr.bin/pkill/pkill.1
--- a/usr.bin/pkill/pkill.1 Mon Dec 06 01:08:02 2010 +0000
+++ b/usr.bin/pkill/pkill.1 Mon Dec 06 04:00:11 2010 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkill.1,v 1.18 2009/02/28 19:21:42 wiz Exp $
+.\" $NetBSD: pkill.1,v 1.19 2010/12/06 04:00:11 mrg Exp $
.\"
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -56,6 +56,9 @@
.Op Fl U Ar uid
.Op Fl u Ar euid
.Op Ar pattern ...
+.Nm prenice
+.Op Ar priority
+.Op Ar pattern ...
.Sh DESCRIPTION
The
.Nm pgrep
@@ -68,7 +71,15 @@
command searches the process table on the running system and signals all
processes that match the criteria given on the command line.
.Pp
-The following options are available:
+The
+.Nm prenice
+command searches the process table on the running system and sets the
+priority of all processes that match the criteria given on the command line.
+.Pp
+The following options are available for
+.Nm pkill
+and
+.Nm pgrep :
.Bl -tag -width xxxxxxxx
.It Fl d Ar delim
Specify a delimiter to be printed between each process ID.
@@ -166,9 +177,10 @@
process will never consider itself or system processes (kernel threads) as
a potential match.
.Sh EXIT STATUS
-.Nm pgrep
+.Nm pgrep ,
+.Nm pkill
and
-.Nm pkill
+.Nm prenice
return one of the following values upon exit:
.Bl -tag -width foo
.It 0
@@ -187,6 +199,7 @@
.Xr kill 2 ,
.Xr sigaction 2 ,
.Xr re_format 7 ,
+.Xr renice 1 ,
.Xr signal 7
.Sh HISTORY
.Nm pkill
@@ -196,3 +209,7 @@
.Nx 1.6 .
They are modelled after utilities of the same name that appeared in Sun
Solaris 7.
+.Pp
+.Nm prenice
+was introduced in
+.Nx 6.0 .
diff -r b77fcd880d44 -r 81e239eca02b usr.bin/pkill/pkill.c
--- a/usr.bin/pkill/pkill.c Mon Dec 06 01:08:02 2010 +0000
+++ b/usr.bin/pkill/pkill.c Mon Dec 06 04:00:11 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pkill.c,v 1.25 2009/04/13 00:12:16 lukem Exp $ */
+/* $NetBSD: pkill.c,v 1.26 2010/12/06 04:00:11 mrg Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pkill.c,v 1.25 2009/04/13 00:12:16 lukem Exp $");
+__RCSID("$NetBSD: pkill.c,v 1.26 2010/12/06 04:00:11 mrg Exp $");
#endif /* !lint */
#include <sys/types.h>
@@ -82,7 +82,9 @@
static const char *delim = "\n";
static int nproc;
static int pgrep;
+static int prenice;
static int signum = SIGTERM;
+static int nicenum;
static int newest;
static int inverse;
static int longfmt;
@@ -103,6 +105,7 @@
int main(int, char **);
static void usage(void) __dead;
static int killact(const struct kinfo_proc2 *);
+static int reniceact(const struct kinfo_proc2 *);
static int grepact(const struct kinfo_proc2 *);
static void makelist(struct listhead *, enum listtype, char *);
@@ -124,6 +127,20 @@
if (strcmp(getprogname(), "pgrep") == 0) {
action = grepact;
pgrep = 1;
+ } else if (strcmp(getprogname(), "prenice") == 0) {
+ prenice = 1;
+ if (argc < 2)
+ usage();
+ action = reniceact;
+ p = argv[1];
+
+ i = (int)strtol(p, &q, 10);
+ if (*q == '\0') {
+ nicenum = i;
+ argv++;
+ argc--;
+ } else
+ usage();
} else {
action = killact;
p = argv[1];
@@ -152,64 +169,66 @@
criteria = 0;
- while ((ch = getopt(argc, argv, "G:P:U:d:fg:ilns:t:u:vx")) != -1)
- switch (ch) {
- case 'G':
- makelist(&rgidlist, LT_GROUP, optarg);
- criteria = 1;
- break;
- case 'P':
- makelist(&ppidlist, LT_GENERIC, optarg);
- criteria = 1;
- break;
- case 'U':
- makelist(&ruidlist, LT_USER, optarg);
- criteria = 1;
- break;
- case 'd':
- if (!pgrep)
+ if (!prenice) {
+ while ((ch = getopt(argc, argv, "G:P:U:d:fg:ilns:t:u:vx")) != -1)
+ switch (ch) {
+ case 'G':
+ makelist(&rgidlist, LT_GROUP, optarg);
+ criteria = 1;
+ break;
+ case 'P':
+ makelist(&ppidlist, LT_GENERIC, optarg);
+ criteria = 1;
+ break;
+ case 'U':
+ makelist(&ruidlist, LT_USER, optarg);
+ criteria = 1;
+ break;
+ case 'd':
+ if (!pgrep)
+ usage();
+ delim = optarg;
+ break;
+ case 'f':
+ matchargs = 1;
+ break;
+ case 'g':
+ makelist(&pgrplist, LT_PGRP, optarg);
+ criteria = 1;
+ break;
+ case 'i':
+ cflags |= REG_ICASE;
+ break;
+ case 'l':
+ longfmt = 1;
+ break;
+ case 'n':
+ newest = 1;
+ criteria = 1;
+ break;
+ case 's':
+ makelist(&sidlist, LT_SID, optarg);
+ criteria = 1;
+ break;
+ case 't':
+ makelist(&tdevlist, LT_TTY, optarg);
+ criteria = 1;
+ break;
+ case 'u':
+ makelist(&euidlist, LT_USER, optarg);
+ criteria = 1;
+ break;
+ case 'v':
+ inverse = 1;
+ break;
+ case 'x':
+ fullmatch = 1;
+ break;
+ default:
usage();
- delim = optarg;
- break;
- case 'f':
- matchargs = 1;
- break;
- case 'g':
- makelist(&pgrplist, LT_PGRP, optarg);
- criteria = 1;
- break;
- case 'i':
- cflags |= REG_ICASE;
- break;
- case 'l':
- longfmt = 1;
- break;
- case 'n':
- newest = 1;
- criteria = 1;
- break;
- case 's':
- makelist(&sidlist, LT_SID, optarg);
- criteria = 1;
- break;
- case 't':
- makelist(&tdevlist, LT_TTY, optarg);
- criteria = 1;
- break;
- case 'u':
- makelist(&euidlist, LT_USER, optarg);
- criteria = 1;
- break;
- case 'v':
- inverse = 1;
- break;
- case 'x':
- fullmatch = 1;
- break;
- default:
- usage();
- /* NOTREACHED */
- }
+ /* NOTREACHED */
+ }
+ }
argc -= optind;
argv += optind;
@@ -407,15 +426,21 @@
{
const char *ustr;
- if (pgrep)
- ustr = "[-filnvx] [-d delim]";
- else
- ustr = "[-signal] [-filnvx]";
+ if (prenice)
+ fprintf(stderr, "Usage: %s priority pattern ...\n",
+ getprogname());
+ else {
+ if (pgrep)
+ ustr = "[-filnvx] [-d delim]";
+ else
+ ustr = "[-signal] [-filnvx]";
- (void)fprintf(stderr,
- "Usage: %s %s [-G gid] [-g pgrp] [-P ppid] [-s sid] [-t tty]\n"
- " [-U uid] [-u euid] pattern ...\n", getprogname(),
- ustr);
+ (void)fprintf(stderr,
+ "Usage: %s %s [-G gid] [-g pgrp] [-P ppid] [-s sid] "
+ "[-t tty]\n"
+ " [-U uid] [-u euid] pattern ...\n",
+ getprogname(), ustr);
+ }
exit(STATUS_BADUSAGE);
}
@@ -447,6 +472,32 @@
}
static int
+reniceact(const struct kinfo_proc2 *kp)
+{
+ int oldprio;
+
+ if (longfmt)
+ grepact(kp);
+
+ errno = 0;
+ if ((oldprio = getpriority(PRIO_PROCESS, kp->p_pid)) == -1 &&
+ errno != 0) {
+ warn("%d: getpriority", kp->p_pid);
+ return 0;
+ }
+
+ if (setpriority(PRIO_PROCESS, kp->p_pid, nicenum) == -1) {
+ warn("%d: setpriority", kp->p_pid);
+ return 0;
+ }
+
+ (void)printf("%d: old priority %d, new priority %d\n",
Home |
Main Index |
Thread Index |
Old Index