2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 1994 David Greenman
5 * Copyright (c) 1994 Henrik Vestergaard Draboel (hvd@terry.ping.dk)
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Henrik Vestergaard Draboel.
19 * This product includes software developed by David Greenman.
20 * 4. Neither the names of the authors nor the names of contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include <sys/param.h>
41 #include <sys/rtprio.h>
51 static int parseint(const char *, const char *);
52 static void usage(void);
55 main(int argc, char *argv[])
61 progname = getprogname();
63 if (strcmp(progname, "rtprio") == 0)
64 rtp.type = RTP_PRIO_REALTIME;
65 else if (strcmp(progname, "idprio") == 0)
66 rtp.type = RTP_PRIO_IDLE;
68 errx(1, "invalid progname");
72 proc = parseint(argv[1], "pid");
76 if (rtprio(RTP_LOOKUP, proc, &rtp) != 0)
79 case RTP_PRIO_REALTIME:
81 warnx("realtime priority %d", rtp.prio);
84 warnx("normal priority");
87 warnx("idle priority %d", rtp.prio);
90 errx(1, "invalid priority type %d", rtp.type);
95 if (argv[1][0] == '-' || isdigit(argv[1][0])) {
96 if (argv[1][0] == '-') {
97 if (strcmp(argv[1], "-t") == 0) {
98 rtp.type = RTP_PRIO_NORMAL;
105 rtp.prio = parseint(argv[1], "priority");
111 if (argv[2][0] == '-') {
112 proc = parseint(argv[2], "pid");
116 if (rtprio(RTP_SET, proc, &rtp) != 0)
120 execvp(argv[2], &argv[2]);
121 err(1, "execvp: %s", argv[2]);
129 parseint(const char *str, const char *errname)
135 res = strtol(str, &endp, 10);
136 if (errno != 0 || endp == str || *endp != '\0')
137 errx(1, "%s must be a number", errname);
139 errx(1, "Integer overflow parsing %s", errname);
147 (void) fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
148 "usage: [id|rt]prio",
149 " [id|rt]prio [-]pid",
150 " [id|rt]prio priority command [args]",
151 " [id|rt]prio priority -pid",
152 " [id|rt]prio -t command [args]",
153 " [id|rt]prio -t -pid");