diff --git a/Makefile b/Makefile index 4e1f3e6..bef596f 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ SRC = \ mkdir.c \ mkfifo.c \ mv.c \ + nice.c \ nl.c \ nohup.c \ paste.c \ diff --git a/nice.1 b/nice.1 new file mode 100644 index 0000000..0803461 --- /dev/null +++ b/nice.1 @@ -0,0 +1,18 @@ +.TH NICE 1 sbase\-VERSION +.SH NAME +nice \- invoke a utility with an altered nice value +.SH SYNOPSIS +.B nice +.RB [ \-n inc ] +.I command +.RI [ options ...] +.SH DESCRIPTION +.B nice +invokes +.IR command +with a nice value equal to the current nice value plus +.IR inc, +which defaults to 10 if unspecified. + +.SH SEE ALSO +.IR renice (1) nice (2) diff --git a/nice.c b/nice.c new file mode 100644 index 0000000..c446b4c --- /dev/null +++ b/nice.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include"util.h" + +static void +usage(){ + eprintf("usage: nice [-n inc] command [options ...]\n"); +} + +int +main(int argc, char **argv){ + int inc = 10; + + ARGBEGIN { + case 'n': + inc = atoi(EARGF(usage())); + break; + default: + usage(); + } ARGEND; + + nice(inc); /* POSIX specifies the nice failure still invokes the command. */ + + if(!*argv) + usage(); + execvp(*argv, argv); + eprintf("nice: '%s': %s\n", *argv, strerror(errno)); + return EXIT_FAILURE; +} +