View | Details | Raw Unified | Return to bug 36950
Collapse All | Expand All

(-)renice.8 (-55 / +68 lines)
Lines 40-129 Link Here
40
.Nd alter priority of running processes
40
.Nd alter priority of running processes
41
.Sh SYNOPSIS
41
.Sh SYNOPSIS
42
.Nm
42
.Nm
43
.Ar priority
43
.Ar nice_value
44
.Oo
44
.Oo
45
.Op Fl p
45
.Fl g |
46
.Ar pid ...
46
.Fl p
47
|
48
.Fl u
47
.Oc
49
.Oc
50
.Ar ID ...
51
.Nm
52
.Fl n Ar increment
48
.Oo
53
.Oo
49
.Op Fl g
54
.Fl g |
50
.Ar pgrp ...
55
.Fl p
51
.Oc
56
|
52
.Oo
57
.Fl u
53
.Op Fl u
54
.Ar user ...
55
.Oc
58
.Oc
59
.Ar ID ...
56
.Sh DESCRIPTION
60
.Sh DESCRIPTION
57
.Nm Renice
61
.Nm Renice
58
alters the
62
alters the
59
scheduling priority of one or more running processes.
63
scheduling priority of one or more running processes.
60
The following
64
By default, the processes to be affected are specified by
61
.Ar who
65
their process ID's.
62
parameters are interpreted as process ID's, process group
66
Specifying
63
ID's, or user names.
64
.Nm Renice Ns 'ing
65
a process group causes all processes in the process group
67
a process group causes all processes in the process group
66
to have their scheduling priority altered.
68
to have their scheduling priority altered.
67
.Nm Renice Ns 'ing
69
Specifying
68
a user causes all processes owned by the user to have
70
a user causes all processes owned by the user to have
69
their scheduling priority altered.
71
their scheduling priority altered.
70
By default, the processes to be affected are specified by
72
.Pp
71
their process ID's.
73
If the requested priority or increment would exceed PRIO_MIN (\-20)
74
or PRIO_MAX (20), the limit that was exceeded is used.
75
Only the superuser may affect the scheduling priority of processes
76
owned by another user.
77
Only the superuser may increase the scheduling priority of a process
78
(decrease the nice_value).
72
.Pp
79
.Pp
73
Options supported by
80
Options supported by
74
.Nm :
81
.Nm :
75
.Bl -tag -width Ds
82
.Bl -tag -width Ds
83
.It Fl n Ar increment
84
Increment the scheduling priority of the specified process.
85
Positive values will decrease the scheduling priority, and negative
86
values will increase the scheduling priority.
87
Only the superuser may specify a negative value.
76
.It Fl g
88
.It Fl g
77
Force
89
Interpret all
78
.Ar who
90
.Ar ID
79
parameters to be interpreted as process group ID's.
91
arguments as unsigned decimal integer process group ID's.
80
.It Fl u
81
Force the
82
.Ar who
83
parameters to be interpreted as user names.
84
.It Fl p
92
.It Fl p
85
Resets the
93
Interpret all
86
.Ar who
94
.Ar ID
87
interpretation to be (the default) process ID's.
95
arguments as unsigned decimal integer process ID's.
96
This is the default if no options are specified.
97
.It Fl u
98
Interpret all
99
.Ar ID
100
arguments as users.
101
The
102
.Ar ID
103
may be a valid user name or an unsigned decimal integer user ID.
88
.El
104
.El
89
.Pp
105
.Pp
90
For example,
106
Useful nice_values are:
91
.Bd -literal -offset
92
renice +1 987 -u daemon root -p 32
93
.Ed
94
.Pp
95
would change the priority of process ID's 987 and 32, and
96
all processes owned by users daemon and root.
97
.Pp
98
Users other than the super-user may only alter the priority of
99
processes they own,
100
and can only monotonically increase their ``nice value''
101
within the range 0 to
102
.Dv PRIO_MAX
103
(20).
104
(This prevents overriding administrative fiats.)
105
The super-user
106
may alter the priority of any process
107
and set the priority to any value in the range
108
.Dv PRIO_MIN
109
(\-20)
110
to
111
.Dv PRIO_MAX .
112
Useful priorities are:
113
20 (the affected processes will run only when nothing else
107
20 (the affected processes will run only when nothing else
114
in the system wants to),
108
in the system wants to),
115
0 (the ``base'' scheduling priority),
109
0 (the ``base'' scheduling priority),
116
anything negative (to make things go very fast).
110
anything negative (to make things go very fast).
117
.Sh FILES
111
.Sh EXAMPLES
118
.Bl -tag -width /etc/passwd -compact
112
Adjust the system scheduling priority so group
119
.It Pa /etc/passwd
113
ID's 69 and 77 have a lower priority:
120
to map user names to user ID's
114
.Pp
121
.El
115
.Dl % renice -n 5 -g 69 77
116
.Pp
117
Adjust the system scheduling priority so process
118
ID's 2987 and 85723 have the lowest priority:
119
.Pp
120
.Dl % renice 20 2987 85723
121
.Pp
122
Adjust the system scheduling priority so user
123
foo and user ID 2000 have higher priority:
124
.Pp
125
.Dl # renice -n -5 -u foo 2000
126
.Pp
122
.Sh SEE ALSO
127
.Sh SEE ALSO
123
.Xr nice 1 ,
128
.Xr nice 1 ,
124
.Xr rtprio 1 ,
129
.Xr rtprio 1 ,
125
.Xr getpriority 2 ,
130
.Xr getpriority 2 ,
126
.Xr setpriority 2
131
.Xr setpriority 2
132
.Sh STANDARDS
133
The
134
.Nm
135
utility conforms to
136
.St -p1003.1-2001
137
Note: Specifying
138
.Ar nice_value
139
is deprecated, but it is accepted due to its historical significance.
127
.Sh BUGS
140
.Sh BUGS
128
Non super-users cannot increase scheduling priorities of their own processes,
141
Non super-users cannot increase scheduling priorities of their own processes,
129
even if they were the ones that decreased the priorities in the first place.
142
even if they were the ones that decreased the priorities in the first place.
(-)renice.c (-45 / +63 lines)
Lines 32-49 Link Here
32
 */
32
 */
33
33
34
#ifndef lint
34
#ifndef lint
35
static const char copyright[] =
35
static char copyright[] =
36
"@(#) Copyright (c) 1983, 1989, 1993\n\
36
"@(#) Copyright (c) 1983, 1989, 1993\n\
37
	The Regents of the University of California.  All rights reserved.\n";
37
	The Regents of the University of California.  All rights reserved.\n";
38
#endif /* not lint */
38
#endif /* not lint */
39
39
40
#ifndef lint
41
#if 0
40
#if 0
41
#ifndef lint
42
static char sccsid[] = "@(#)renice.c	8.1 (Berkeley) 6/9/93";
42
static char sccsid[] = "@(#)renice.c	8.1 (Berkeley) 6/9/93";
43
#endif
44
static const char rcsid[] =
45
  "$FreeBSD: src/usr.bin/renice/renice.c,v 1.8 2002/03/22 01:33:21 imp Exp $";
46
#endif /* not lint */
43
#endif /* not lint */
44
#endif
45
46
#include <sys/cdefs.h>
47
__FBSDID("$FreeBSD$");
47
48
48
#include <sys/types.h>
49
#include <sys/types.h>
49
#include <sys/time.h>
50
#include <sys/time.h>
Lines 51-62 Link Here
51
52
52
#include <err.h>
53
#include <err.h>
53
#include <errno.h>
54
#include <errno.h>
55
#include <limits.h>
56
#include <pwd.h>
54
#include <stdio.h>
57
#include <stdio.h>
55
#include <stdlib.h>
58
#include <stdlib.h>
56
#include <string.h>
59
#include <string.h>
57
#include <pwd.h>
60
#include <sysexits.h>
58
61
59
int donice(int, int, int);
62
static int donice(int, int, int, int);
60
static void usage(void);
63
static void usage(void);
61
64
62
/*
65
/*
Lines 65-130 Link Here
65
 * running.
68
 * running.
66
 */
69
 */
67
int
70
int
68
main(argc, argv)
71
main(int argc, char *argv[])
69
	int argc;
70
	char **argv;
71
{
72
{
72
	int which = PRIO_PROCESS;
73
	struct passwd *pwd;
73
	int who = 0, prio, errs = 0;
74
	char *endptr;
75
	int errs, nflag, prio, which, who;
76
77
	which = PRIO_PROCESS;
78
	errs = 0, nflag = 0, who = 0;
74
79
75
	argc--, argv++;
80
	argc--, argv++;
76
	if (argc < 2)
81
	if (argc < 2)
77
		usage();
82
		usage();
78
	prio = atoi(*argv);
83
84
	/* Parse priority or -n increment. */
85
	if (strcmp(*argv, "-n") == 0) {
86
		nflag = 1;
87
		argc--, argv++;
88
		if (argc < 2)
89
			usage();
90
	}
91
	prio = strtol(*argv, &endptr, 10);
92
	if (*endptr ||
93
	    ((prio == LONG_MAX || prio == LONG_MIN) && errno == ERANGE))
94
		errx(EX_DATAERR, "Invalid input: %s", *argv);
79
	argc--, argv++;
95
	argc--, argv++;
80
	if (prio > PRIO_MAX)
96
81
		prio = PRIO_MAX;
97
	/*
82
	if (prio < PRIO_MIN)
98
	 * Accept -g, -p, -u, or a number. If it's a number, default
83
		prio = PRIO_MIN;
99
	 * to -p (PRIO_PROCESS).
100
	 */
101
	if (strcmp(*argv, "-g") == 0) {
102
		which = PRIO_PGRP;
103
		argc--, argv++;
104
	} else if (strcmp(*argv, "-u") == 0) {
105
		which = PRIO_USER;
106
		argc--, argv++;
107
	} else if (strcmp(*argv, "-p") == 0)
108
		argc--, argv++;
109
84
	for (; argc > 0; argc--, argv++) {
110
	for (; argc > 0; argc--, argv++) {
85
		if (strcmp(*argv, "-g") == 0) {
111
		who = strtoul(*argv, &endptr, 10);
86
			which = PRIO_PGRP;
112
87
			continue;
113
		/* If argv is not a number, then we should be PRIO_USER. */
88
		}
114
		if ((*endptr && which != PRIO_USER) ||
89
		if (strcmp(*argv, "-u") == 0) {
115
		    ((who == LONG_MAX || who == LONG_MIN) && errno == ERANGE)) {
90
			which = PRIO_USER;
116
			warnx("Invalid input: %s", *argv);
91
			continue;
92
		}
93
		if (strcmp(*argv, "-p") == 0) {
94
			which = PRIO_PROCESS;
95
			continue;
117
			continue;
96
		}
118
		}
97
		if (which == PRIO_USER) {
119
		if (which == PRIO_USER && *endptr) {
98
			register struct passwd *pwd = getpwnam(*argv);
120
			pwd = getpwnam(*argv);
99
121
100
			if (pwd == NULL) {
122
			if (pwd == NULL) {
101
				warnx("%s: unknown user", *argv);
123
				warnx("%s: unknown user", *argv);
102
				continue;
124
				continue;
103
			}
125
			}
104
			who = pwd->pw_uid;
126
			who = pwd->pw_uid;
105
		} else {
106
			who = atoi(*argv);
107
			if (who < 0) {
108
				warnx("%s: bad value", *argv);
109
				continue;
110
			}
111
		}
127
		}
112
		errs += donice(which, who, prio);
128
		errs += donice(which, who, prio, nflag);
113
	}
129
	}
114
	exit(errs != 0);
130
	exit(errs);
115
}
131
}
116
132
117
static void
133
static void
118
usage()
134
usage(void)
119
{
135
{
120
	fprintf(stderr,
136
121
"usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\n");
137
	fprintf(stderr, "usage: renice nice_value [-g | -p | -u] ID ...\n");
122
	exit(1);
138
	fprintf(stderr, "       renice -n increment [-g | -p | -u] ID ...\n");
139
	exit(EX_USAGE);
123
}
140
}
124
141
125
int
142
static int
126
donice(which, who, prio)
143
donice(int which, int who, int prio, int nflag)
127
	int which, who, prio;
128
{
144
{
129
	int oldprio;
145
	int oldprio;
130
146
Lines 133-142 Link Here
133
		warn("%d: getpriority", who);
149
		warn("%d: getpriority", who);
134
		return (1);
150
		return (1);
135
	}
151
	}
152
	if (nflag)
153
		prio += oldprio; /* Possible over/underflow here. */
136
	if (setpriority(which, who, prio) < 0) {
154
	if (setpriority(which, who, prio) < 0) {
137
		warn("%d: setpriority", who);
155
		warn("%d: setpriority", who);
138
		return (1);
156
		return (1);
139
	}
157
	}
140
	printf("%d: old priority %d, new priority %d\n", who, oldprio, prio);
158
	printf("%d: old nice_value %d, new nice_value %d\n", who, oldprio, prio);
141
	return (0);
159
	return (0);
142
}
160
}

Return to bug 36950