From 9c8047a9395e1ca043a0b76d666b66fe4db410b3 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 31 Jul 2013 16:36:57 -0500 Subject: Move renice from pending to posix, default y, fix link to standard. --- toys/posix/renice.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 toys/posix/renice.c (limited to 'toys/posix/renice.c') diff --git a/toys/posix/renice.c b/toys/posix/renice.c new file mode 100644 index 00000000..8c206447 --- /dev/null +++ b/toys/posix/renice.c @@ -0,0 +1,48 @@ +/* renice.c - renice process + * + * Copyright 2013 CE Strake + * + * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/renice.html + +USE_RENICE(NEWTOY(renice, "<1gpun#|", TOYFLAG_BIN)) + +config RENICE + bool "renice" + default y + help + usage: renice [-gpu] -n increment ID ... +*/ + +#define FOR_renice +#include "toys.h" + +GLOBALS( + long nArgu; +) + +void renice_main(void) { + int which = (toys.optflags & FLAG_g) ? PRIO_PGRP : + ((toys.optflags & FLAG_u) ? PRIO_USER : PRIO_PROCESS); + char **arg; + + for (arg = toys.optargs; *arg; arg++) { + char *s = *arg; + int id = -1; + + if (toys.optflags & FLAG_u) { + struct passwd *p = getpwnam(s); + if (p) id = p->pw_uid; + } else { + id = strtol(s, &s, 10); + if (*s) id = -1; + } + + if (id < 0) { + error_msg("bad '%s'", *arg); + continue; + } + + if (setpriority(which, id, getpriority(which, id)+TT.nArgu) < 0) + perror_msg("setpriority %d", id); + } +} -- cgit v1.2.3