setpriority() { register struct a { int which; int who; int prio; } *uap = (struct a *)u.u_ap; register struct proc *p; int found = 0; switch (uap->which) { case PRIO_PROCESS: if (uap->who == 0) p = u.u_procp; else p = pfind(uap->who); if (p == 0) break; donice(p, uap->prio); found++; break; case PRIO_PGRP: if (uap->who == 0) uap->who = u.u_procp->p_pgrp; for (p = allproc; p != NULL; p = p->p_nxt) if (p->p_pgrp == uap->who) { donice(p, uap->prio); found++; } break; case PRIO_USER: if (uap->who == 0) uap->who = u.u_uid; for (p = allproc; p != NULL; p = p->p_nxt) if (p->p_uid == uap->who) { donice(p, uap->prio); found++; } break; default: u.u_error = EINVAL; return; } if (found == 0) u.u_error = ESRCH; }
/* * Change the priority (the nice value) of processes * or groups of processes which are already running. */ int main(int argc, char **argv) { int which = PRIO_PROCESS; int who = 0, prio, errs = 0; char *endptr = NULL; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); argc--; argv++; if (argc == 1) { if (strcmp(*argv, "-h") == 0 || strcmp(*argv, "--help") == 0) usage(stdout); if (strcmp(*argv, "-v") == 0 || strcmp(*argv, "-V") == 0 || strcmp(*argv, "--version") == 0) { printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING); exit(EXIT_SUCCESS); } } if (argc < 2) usage(stderr); if (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--priority") == 0) { argc--; argv++; } prio = strtol(*argv, &endptr, 10); if (*endptr) usage(stderr); argc--; argv++; for (; argc > 0; argc--, argv++) { if (strcmp(*argv, "-g") == 0 || strcmp(*argv, "--pgrp") == 0) { which = PRIO_PGRP; continue; } if (strcmp(*argv, "-u") == 0 || strcmp(*argv, "--user") == 0) { which = PRIO_USER; continue; } if (strcmp(*argv, "-p") == 0 || strcmp(*argv, "--pid") == 0) { which = PRIO_PROCESS; continue; } if (which == PRIO_USER) { register struct passwd *pwd = getpwnam(*argv); if (pwd == NULL) { warnx(_("unknown user %s"), *argv); continue; } who = pwd->pw_uid; } else { who = strtol(*argv, &endptr, 10); if (who < 0 || *endptr) { warnx(_("bad value %s"), *argv); continue; } } errs += donice(which, who, prio); } return errs != 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
/* * Change the priority (the nice value) of processes * or groups of processes which are already running. */ int main(int argc, char **argv) { int which = PRIO_PROCESS; int who = 0, prio, errs = 0; char *endptr = NULL; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); argc--; argv++; if (argc == 1) { if (strcmp(*argv, "-h") == 0 || strcmp(*argv, "--help") == 0) usage(stdout); if (strcmp(*argv, "-v") == 0 || strcmp(*argv, "-V") == 0 || strcmp(*argv, "--version") == 0) { printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; } } if (*argv && (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--priority") == 0)) { argc--; argv++; } if (argc < 2) usage(stderr); prio = strtol(*argv, &endptr, 10); if (*endptr) usage(stderr); argc--; argv++; for (; argc > 0; argc--, argv++) { if (strcmp(*argv, "-g") == 0 || strcmp(*argv, "--pgrp") == 0) { which = PRIO_PGRP; continue; } if (strcmp(*argv, "-u") == 0 || strcmp(*argv, "--user") == 0) { which = PRIO_USER; continue; } if (strcmp(*argv, "-p") == 0 || strcmp(*argv, "--pid") == 0) { which = PRIO_PROCESS; continue; } if (which == PRIO_USER) { struct passwd *pwd = getpwnam(*argv); if (pwd != NULL) who = pwd->pw_uid; else who = strtol(*argv, &endptr, 10); if (who < 0 || *endptr) { warnx(_("unknown user %s"), *argv); errs = 1; continue; } } else { who = strtol(*argv, &endptr, 10); if (who < 0 || *endptr) { /* TRANSLATORS: The first %s is one of the above * three ID names. Read: "bad value for %s: %s" */ warnx(_("bad %s value: %s"), idtype[which], *argv); errs = 1; continue; } } errs |= donice(which, who, prio); } return errs != 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
/* * Change the priority (nice) of processes * or groups of processes which are already * running. */ int main(int argc, char *argv[]) { struct passwd *pwd; int errs, incr, prio, which, who; errs = 0; incr = 0; which = PRIO_PROCESS; who = 0; argc--, argv++; if (argc < 2) usage(); if (strcmp(*argv, "-n") == 0) { incr = 1; argc--, argv++; if (argc < 2) usage(); } if (getnum("priority", *argv, &prio)) return (1); argc--, argv++; for (; argc > 0; argc--, argv++) { if (strcmp(*argv, "-g") == 0) { which = PRIO_PGRP; continue; } if (strcmp(*argv, "-u") == 0) { which = PRIO_USER; continue; } if (strcmp(*argv, "-p") == 0) { which = PRIO_PROCESS; continue; } if (which == PRIO_USER) { if ((pwd = getpwnam(*argv)) != NULL) who = pwd->pw_uid; else if (getnum("uid", *argv, &who)) { errs++; continue; } else if (who < 0) { warnx("%s: bad value", *argv); errs++; continue; } } else { if (getnum("pid", *argv, &who)) { errs++; continue; } if (who < 0) { warnx("%s: bad value", *argv); errs++; continue; } } errs += donice(which, who, prio, incr); } exit(errs != 0); }