From: Apple Date: Thu, 10 Dec 2009 03:28:52 +0000 (+0000) Subject: system_cmds-498.2.tar.gz X-Git-Tag: mac-os-x-1064^0 X-Git-Url: https://git.saurik.com/apple/system_cmds.git/commitdiff_plain/fa62d991a164ca3b9c2d6311b462257aea81aded system_cmds-498.2.tar.gz --- diff --git a/Makefile b/Makefile index 03324f3..ff782bf 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ SubProjects = ac.tproj accton.tproj arch.tproj bootlog.tproj \ ifeq "$(Embedded)" "NO" SubProjects += at.tproj atrun.tproj \ chkpasswd.tproj chpass.tproj dirhelper.tproj shutdown.tproj +else +SubProjects += mean.tproj endif Extra_LD_Flags += -lcurses -lutil diff --git a/mean.tproj/Makefile b/mean.tproj/Makefile new file mode 100644 index 0000000..97ab226 --- /dev/null +++ b/mean.tproj/Makefile @@ -0,0 +1,9 @@ +Project = mean +Install_Dir = /usr/local/bin/ + +CFILES = mean.c + +Extra_CC_Flags = -Wall -Werror + +include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make + diff --git a/mean.tproj/mean.c b/mean.tproj/mean.c new file mode 100644 index 0000000..9e56018 --- /dev/null +++ b/mean.tproj/mean.c @@ -0,0 +1,116 @@ +/* + * mean.c + * mean - lower process priorities with more force than nice + * + * Created by Lucia Ballard on 9/16/09. + * Copyright 2009 Apple Inc. All rights reserved. + * + */ + +#include +#include + +#include + +#include +#include +#include +#include + +void usage(void); + +#ifndef PRIO_DARWIN_PROCESS +#define PRIO_DARWIN_PROCESS 4 /* Second argument is a PID */ +#endif + +void +usage(void) +{ + fprintf(stderr, "Usage: mean -t \n"); + fprintf(stderr, "\tthrottle 's usage of cpu, I/O, and networking\n"); + fprintf(stderr, "mean -u \n"); + fprintf(stderr, "\treturn to normal priority\n"); + fprintf(stderr, "mean -[s|r] \n"); + fprintf(stderr, "\tsuspend or resume \n"); + exit(0); +} + +int +main(int argc, char **argv) +{ + int pid, err, ch; + mach_port_t task; + int priority = 0; + + boolean_t do_resume = 0, do_suspend = 0; + boolean_t do_throttle = 0, do_undo = 0; + + if (argc < 2) + usage(); + + while ((ch = getopt(argc, argv, "rstu")) != -1) + switch (ch) { + case 'u': + do_undo = 1; + continue; + case 'r': + do_resume = 1; + continue; + case 's': + do_suspend = 1; + continue; + case 't': + do_throttle = 1; + continue; + default: + usage(); + } + + argc -= optind; argv += optind; + + if (argc == 0) + usage(); + + pid = atoi(*argv); + if (!pid) + usage(); + + if (do_throttle || do_undo) { + priority = PRIO_DARWIN_BG; + + if (do_undo) + priority = 0; + + err = setpriority(PRIO_DARWIN_PROCESS, pid, priority); + if (err) { + fprintf(stderr, "Failed to set priority (%d)\n", errno); + exit(0); + } + } + + if (do_suspend || do_resume) { + err = task_for_pid(mach_task_self(), pid, &task); + if (err) { + fprintf(stderr, "Failed to get task port (%d)\n", err); + exit(0); + } + + if (do_suspend) { + err = task_suspend(task); + if (err) { + fprintf(stderr, "Failed to suspend task (%d)\n", err); + } + + } + + if (do_resume) { + err = task_resume(task); + if (err) { + fprintf(stderr, "Failed to resume task (%d)\n", err); + } + } + } + + return 0; +} +