]>
git.saurik.com Git - apple/system_cmds.git/blob - mean.tproj/mean.c
9e5601810b819e7face057cf319d5a04a37c00bd
3 * mean - lower process priorities with more force than nice
5 * Created by Lucia Ballard on 9/16/09.
6 * Copyright 2009 Apple Inc. All rights reserved.
10 #include <mach/mach.h>
11 #include <mach/task.h>
13 #include <sys/resource.h>
22 #ifndef PRIO_DARWIN_PROCESS
23 #define PRIO_DARWIN_PROCESS 4 /* Second argument is a PID */
29 fprintf(stderr
, "Usage: mean -t <pid>\n");
30 fprintf(stderr
, "\tthrottle <pid>'s usage of cpu, I/O, and networking\n");
31 fprintf(stderr
, "mean -u <pid>\n");
32 fprintf(stderr
, "\treturn <pid> to normal priority\n");
33 fprintf(stderr
, "mean -[s|r] <pid>\n");
34 fprintf(stderr
, "\tsuspend or resume <pid>\n");
39 main(int argc
, char **argv
)
45 boolean_t do_resume
= 0, do_suspend
= 0;
46 boolean_t do_throttle
= 0, do_undo
= 0;
51 while ((ch
= getopt(argc
, argv
, "rstu")) != -1)
69 argc
-= optind
; argv
+= optind
;
78 if (do_throttle
|| do_undo
) {
79 priority
= PRIO_DARWIN_BG
;
84 err
= setpriority(PRIO_DARWIN_PROCESS
, pid
, priority
);
86 fprintf(stderr
, "Failed to set priority (%d)\n", errno
);
91 if (do_suspend
|| do_resume
) {
92 err
= task_for_pid(mach_task_self(), pid
, &task
);
94 fprintf(stderr
, "Failed to get task port (%d)\n", err
);
99 err
= task_suspend(task
);
101 fprintf(stderr
, "Failed to suspend task (%d)\n", err
);
107 err
= task_resume(task
);
109 fprintf(stderr
, "Failed to resume task (%d)\n", err
);