xref: /csrg-svn/usr.bin/nice/nice.c (revision 19845)
1*19845Sdist /*
2*19845Sdist  * Copyright (c) 1980 Regents of the University of California.
3*19845Sdist  * All rights reserved.  The Berkeley software License Agreement
4*19845Sdist  * specifies the terms and conditions for redistribution.
5*19845Sdist  */
6*19845Sdist 
712669Ssam #ifndef lint
8*19845Sdist char copyright[] =
9*19845Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
10*19845Sdist  All rights reserved.\n";
11*19845Sdist #endif not lint
121059Sbill 
13*19845Sdist #ifndef lint
14*19845Sdist static char sccsid[] = "@(#)nice.c	5.1 (Berkeley) 04/30/85";
15*19845Sdist #endif not lint
16*19845Sdist 
171059Sbill #include <stdio.h>
181059Sbill 
1912669Ssam #include <sys/time.h>
2012669Ssam #include <sys/resource.h>
2112669Ssam 
221059Sbill main(argc, argv)
2312669Ssam 	int argc;
2412669Ssam 	char *argv[];
251059Sbill {
261059Sbill 	int nicarg = 10;
271059Sbill 
2812669Ssam 	if (argc > 1 && argv[1][0] == '-') {
291059Sbill 		nicarg = atoi(&argv[1][1]);
3012669Ssam 		argc--, argv++;
311059Sbill 	}
3212669Ssam 	if (argc < 2) {
331059Sbill 		fputs("usage: nice [ -n ] command\n", stderr);
341059Sbill 		exit(1);
351059Sbill 	}
3612669Ssam 	if (setpriority(PRIO_PROCESS, 0, nicarg) < 0) {
3712669Ssam 		perror("setpriority");
3812669Ssam 		exit(1);
3912669Ssam 	}
401059Sbill 	execvp(argv[1], &argv[1]);
4112669Ssam 	perror(argv[1]);
421059Sbill 	exit(1);
431059Sbill }
44