|
|
1.1 root 1: /*
2: * Copyright (c) 1989 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: char copyright[] =
22: "@(#) Copyright (c) 1989 The Regents of the University of California.\n\
23: All rights reserved.\n";
24: #endif /* not lint */
25:
26: #ifndef lint
27: static char sccsid[] = "@(#)nice.c 5.4 (Berkeley) 6/1/90";
28: #endif /* not lint */
29:
30: #include <sys/time.h>
31: #include <sys/resource.h>
32: #include <stdio.h>
33: #include <ctype.h>
34:
35: #define DEFNICE 10
36:
37: /* ARGSUSED */
38: main(argc, argv)
39: int argc;
40: char **argv;
41: {
42: extern int errno;
43: int niceness;
44: char *strerror();
45:
46: niceness = DEFNICE;
47: if (argv[1][0] == '-')
48: if (isdigit(argv[1][1])) {
49: niceness = atoi(argv[1] + 1);
50: ++argv;
51: }
52: else {
53: (void)fprintf(stderr, "nice: illegal option -- %c\n",
54: argv[1][1]);
55: usage();
56: }
57:
58: if (!argv[1])
59: usage();
60:
61: errno = 0;
62: niceness += getpriority(PRIO_PROCESS, 0);
63: if (errno) {
64: (void)fprintf(stderr, "nice: getpriority: %s\n",
65: strerror(errno));
66: exit(1);
67: }
68: if (setpriority(PRIO_PROCESS, 0, niceness)) {
69: (void)fprintf(stderr,
70: "nice: setpriority: %s\n", strerror(errno));
71: exit(1);
72: }
73: execvp(argv[1], &argv[1]);
74: (void)fprintf(stderr,
75: "nice: %s: %s\n", argv[1], strerror(errno));
76: exit(1);
77: }
78:
79: usage()
80: {
81: (void)fprintf(stderr,
82: "nice [ -# ] command [ options ] [ operands ]\n");
83: exit(1);
84: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.