119845Sdist /*
266806Sbostic * Copyright (c) 1989, 1993, 1994
362149Sbostic * The Regents of the University of California. All rights reserved.
438087Sbostic *
542755Sbostic * %sccs.include.redist.c%
619845Sdist */
719845Sdist
812669Ssam #ifndef lint
962149Sbostic static char copyright[] =
1066806Sbostic "@(#) Copyright (c) 1989, 1993, 1994\n\
1162149Sbostic The Regents of the University of California. All rights reserved.\n";
1238087Sbostic #endif /* not lint */
131059Sbill
1419845Sdist #ifndef lint
15*69024Sbostic static char sccsid[] = "@(#)nice.c 8.3 (Berkeley) 04/28/95";
1638087Sbostic #endif /* not lint */
1719845Sdist
1854037Sbostic #include <sys/types.h>
1912669Ssam #include <sys/time.h>
2012669Ssam #include <sys/resource.h>
2154037Sbostic
2257921Sbostic #include <ctype.h>
2366806Sbostic #include <err.h>
2457921Sbostic #include <errno.h>
2538087Sbostic #include <stdio.h>
2657921Sbostic #include <stdlib.h>
2757921Sbostic #include <unistd.h>
2857921Sbostic #include <string.h>
2912669Ssam
3038087Sbostic #define DEFNICE 10
3138087Sbostic
3257921Sbostic void usage __P((void));
3357921Sbostic
3457921Sbostic int
main(argc,argv)351059Sbill main(argc, argv)
3612669Ssam int argc;
3757921Sbostic char *argv[];
381059Sbill {
3966806Sbostic int niceness = DEFNICE;
401059Sbill
41*69024Sbostic if (argv[1] == NULL)
42*69024Sbostic usage();
4338087Sbostic if (argv[1][0] == '-')
4466806Sbostic if (argv[1][1] == '-' || isdigit(argv[1][1])) {
4538087Sbostic niceness = atoi(argv[1] + 1);
4638087Sbostic ++argv;
47*69024Sbostic if (argv[1] == NULL)
48*69024Sbostic usage();
4966806Sbostic } else
5066806Sbostic errx(1, "illegal option -- %s", argv[1]);
5138087Sbostic
5238087Sbostic errno = 0;
5338087Sbostic niceness += getpriority(PRIO_PROCESS, 0);
5466806Sbostic if (errno)
5566806Sbostic err(1, "getpriority");
5666806Sbostic if (setpriority(PRIO_PROCESS, 0, niceness))
5766806Sbostic err(1, "setpriority");
581059Sbill execvp(argv[1], &argv[1]);
5966806Sbostic err(1, "%s", argv[1]);
601059Sbill }
6138087Sbostic
6257921Sbostic void
usage()6338087Sbostic usage()
6438087Sbostic {
6538087Sbostic (void)fprintf(stderr,
6638087Sbostic "nice [ -# ] command [ options ] [ operands ]\n");
6738087Sbostic exit(1);
6838087Sbostic }
69