changeset 977:9a96527bea94

Add renice.
author M. Farkas-Dyck <strake888@gmail.com>
date Mon, 29 Jul 2013 21:16:55 -0500
parents f84dd3473233
children 6d3c39cb8a9d
files toys/pending/renice.c
diffstat 1 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toys/pending/renice.c	Mon Jul 29 21:16:55 2013 -0500
@@ -0,0 +1,48 @@
+/* renice.c - renice process
+ *
+ * Copyright 2013 CE Strake <strake888 at gmail.com>
+ *
+ * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/
+ * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html
+
+USE_RENICE(NEWTOY(renice, "gpun#", TOYFLAG_BIN))
+
+config RENICE
+  bool "renice"
+  default n
+  help
+    usage: renice [-gpu] -n increment ID ...
+*/
+
+#define FOR_renice
+#include "toys.h"
+
+GLOBALS(
+  long nArgu;
+)
+
+void renice_main (void) {
+  int ii;
+  int which = toys.optflags & FLAG_g ? PRIO_PGRP :
+              toys.optflags & FLAG_u ? PRIO_USER :
+              PRIO_PROCESS;
+
+  if (!(toys.optflags & FLAG_n)) error_exit ("no increment given");
+
+  for (ii = 0; ii < toys.optc; ii++) {
+    id_t id;
+
+    if (isdigit (toys.optargs[ii][0])) id = strtoul (toys.optargs[ii], 0, 10);
+    else if (toys.optflags & FLAG_u) id = getpwnam (toys.optargs[ii]) -> pw_uid;
+    else {
+      error_msg ("not a number: %s", toys.optargs[ii]);
+      toys.exitval = 1;
+      continue;
+    }
+
+    if (setpriority (which, id, getpriority (which, id) + TT.nArgu) < 0) {
+      error_msg ("failed to setpriority of %d", id);
+      toys.exitval = 1;
+    }
+  }
+}