5 // Created by Christopher Deppe on 3/31/17.
12 #include <sys/sysctl.h>
13 #include <stack_logging.h>
15 #define BSD_PID_MAX 99999 /* Copy of PID_MAX from sys/proc_internal.h. */
17 static void print_usage()
19 printf("usage: mslutil pid [--disable] | [--enable malloc | vm | full | lite]\n");
22 static int send_msl_command(uint64_t pid
, uint64_t flavor
)
24 uint64_t flags
= flavor
;
27 flags
|= (pid
& 0xFFFFFFFF);
29 int ret
= sysctlbyname("kern.memorystatus_vm_pressure_send", 0, 0, &flags
, sizeof(flags
));
32 printf("send_msl_command - sysctl: kern.memorystatus_vm_pressure_send failed %s\n", strerror(errno
));
34 printf("send_msl_command - success!\n");
40 int main(int argc
, const char * argv
[])
49 pid_t pid
= atoi(argv
[1]);
51 if (pid
<= 0 || pid
> BSD_PID_MAX
) {
52 printf("Invalid pid\n");
56 if (strcmp(argv
[2], "--enable") == 0) {
64 if (strcmp(argv
[3], "full") == 0) {
65 flavor
= MEMORYSTATUS_ENABLE_MSL_MALLOC
| MEMORYSTATUS_ENABLE_MSL_VM
;
66 } else if (strcmp(argv
[3], "malloc") == 0) {
67 flavor
= MEMORYSTATUS_ENABLE_MSL_MALLOC
;
68 } else if (strcmp(argv
[3], "vm") == 0) {
69 flavor
= MEMORYSTATUS_ENABLE_MSL_VM
;
70 } else if (strcmp(argv
[3], "lite") == 0) {
71 flavor
= MEMORYSTATUS_ENABLE_MSL_LITE
;
79 ret
= send_msl_command(pid
, flavor
);
80 } else if (strcmp(argv
[2], "--disable") == 0) {
81 ret
= send_msl_command(pid
, MEMORYSTATUS_DISABLE_MSL
);