00001 /* 00002 nice command 00003 AUP2, Sec. 5.15 00004 00005 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00006 May be copied only for purposes and under conditions described 00007 on the Web page www.basepath.com/aup/copyright.htm. 00008 00009 The Example Files are provided "as is," without any warranty; 00010 without even the implied warranty of merchantability or fitness 00011 for a particular purpose. The author and his publisher are not 00012 responsible for any damages, direct or incidental, resulting 00013 from the use or non-use of these Example Files. 00014 00015 The Example Files may contain defects, and some contain deliberate 00016 coding mistakes that were included for educational reasons. 00017 You are responsible for determining if and how the Example Files 00018 are to be used. 00019 00020 */ 00021 #include "defs.h" 00022 00023 /*[aupnice]*/ 00024 #define USAGE "usage: aupnice [-num] command\n" 00025 00026 int main(int argc, char *argv[]) 00027 { 00028 int incr, cmdarg; 00029 char *cmdname, *cmdpath; 00030 00031 if (argc < 2) { 00032 fprintf(stderr, USAGE); 00033 exit(EXIT_FAILURE); 00034 } 00035 if (argv[1][0] == '-') { 00036 incr = atoi(&argv[1][1]); 00037 cmdarg = 2; 00038 } 00039 else { 00040 incr = 10; 00041 cmdarg = 1; 00042 } 00043 if (cmdarg >= argc) { 00044 fprintf(stderr, USAGE); 00045 exit(EXIT_FAILURE); 00046 } 00047 (void)nice(incr); 00048 cmdname = strchr(argv[cmdarg], '/'); 00049 if (cmdname == NULL) 00050 cmdname = argv[cmdarg]; 00051 else 00052 cmdname++; 00053 cmdpath = argv[cmdarg]; 00054 argv[cmdarg] = cmdname; 00055 execvp(cmdpath, &argv[cmdarg]); 00056 EC_FAIL 00057 00058 EC_CLEANUP_BGN 00059 exit(EXIT_FAILURE); 00060 EC_CLEANUP_END 00061 } 00062 /*[]*/