5 #include <sys/resource.h>
13 void cpu_affinity(int cpu
)
16 cpu_set_t cpu_bitmask
;
18 CPU_ZERO(&cpu_bitmask
);
19 CPU_SET(cpu
, &cpu_bitmask
);
21 ret
= sched_setaffinity(getpid(), sizeof(cpu_bitmask
),
24 panic("Can't set this cpu affinity!\n");
27 int set_proc_prio(int priority
)
29 int ret
= setpriority(PRIO_PROCESS
, getpid(), priority
);
31 panic("Can't set nice val to %i!\n", priority
);
36 int set_sched_status(int policy
, int priority
)
38 int ret
, min_prio
, max_prio
;
39 struct sched_param sp
;
41 max_prio
= sched_get_priority_max(policy
);
42 min_prio
= sched_get_priority_min(policy
);
44 if (max_prio
== -1 || min_prio
== -1)
45 printf("Cannot determine scheduler prio limits!\n");
46 else if (priority
< min_prio
)
48 else if (priority
> max_prio
)
51 memset(&sp
, 0, sizeof(sp
));
52 sp
.sched_priority
= priority
;
54 ret
= sched_setscheduler(getpid(), policy
, &sp
);
56 printf("Cannot set scheduler policy!\n");
60 ret
= sched_setparam(getpid(), &sp
);
62 printf("Cannot set scheduler prio!\n");
69 ssize_t
proc_get_cmdline(unsigned int pid
, char *cmdline
, size_t len
)
74 snprintf(path
, sizeof(path
), "/proc/%u/exe", pid
);
75 ret
= readlink(path
, cmdline
, len
- 1);
84 int proc_exec(const char *proc
, char *const argv
[])
93 } else if (pid
== 0) {
94 if (execvp(proc
, argv
) < 0)
95 fprintf(stderr
, "Failed to exec: %s\n", proc
);
99 if (waitpid(pid
, &status
, 0) < 0) {
104 if (!WIFEXITED(status
))
105 return -WEXITSTATUS(status
);