10f66f451Sopenharmony_ci/* renice.c - renice process 20f66f451Sopenharmony_ci * 30f66f451Sopenharmony_ci * Copyright 2013 CE Strake <strake888 at gmail.com> 40f66f451Sopenharmony_ci * 50f66f451Sopenharmony_ci * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/renice.html 60f66f451Sopenharmony_ci 70f66f451Sopenharmony_ciUSE_RENICE(NEWTOY(renice, "<1gpun#|", TOYFLAG_USR|TOYFLAG_BIN)) 80f66f451Sopenharmony_ci 90f66f451Sopenharmony_ciconfig RENICE 100f66f451Sopenharmony_ci bool "renice" 110f66f451Sopenharmony_ci default y 120f66f451Sopenharmony_ci help 130f66f451Sopenharmony_ci usage: renice [-gpu] -n INCREMENT ID... 140f66f451Sopenharmony_ci*/ 150f66f451Sopenharmony_ci 160f66f451Sopenharmony_ci#define FOR_renice 170f66f451Sopenharmony_ci#include "toys.h" 180f66f451Sopenharmony_ci 190f66f451Sopenharmony_ciGLOBALS( 200f66f451Sopenharmony_ci long n; 210f66f451Sopenharmony_ci) 220f66f451Sopenharmony_ci 230f66f451Sopenharmony_civoid renice_main(void) { 240f66f451Sopenharmony_ci int which = (toys.optflags & FLAG_g) ? PRIO_PGRP : 250f66f451Sopenharmony_ci ((toys.optflags & FLAG_u) ? PRIO_USER : PRIO_PROCESS); 260f66f451Sopenharmony_ci char **arg; 270f66f451Sopenharmony_ci 280f66f451Sopenharmony_ci for (arg = toys.optargs; *arg; arg++) { 290f66f451Sopenharmony_ci char *s = *arg; 300f66f451Sopenharmony_ci int id = -1; 310f66f451Sopenharmony_ci 320f66f451Sopenharmony_ci if (toys.optflags & FLAG_u) { 330f66f451Sopenharmony_ci struct passwd *p = getpwnam(s); 340f66f451Sopenharmony_ci if (p) id = p->pw_uid; 350f66f451Sopenharmony_ci } else { 360f66f451Sopenharmony_ci id = strtol(s, &s, 10); 370f66f451Sopenharmony_ci if (*s) id = -1; 380f66f451Sopenharmony_ci } 390f66f451Sopenharmony_ci 400f66f451Sopenharmony_ci if (id < 0) { 410f66f451Sopenharmony_ci error_msg("bad '%s'", *arg); 420f66f451Sopenharmony_ci continue; 430f66f451Sopenharmony_ci } 440f66f451Sopenharmony_ci 450f66f451Sopenharmony_ci if (setpriority(which, id, getpriority(which, id)+TT.n) < 0) 460f66f451Sopenharmony_ci perror_msg("setpriority %d", id); 470f66f451Sopenharmony_ci } 480f66f451Sopenharmony_ci} 49