4 #include <sys/resource.h>
12 void cpu_affinity(int cpu
)
15 cpu_set_t cpu_bitmask
;
17 CPU_ZERO(&cpu_bitmask
);
18 CPU_SET(cpu
, &cpu_bitmask
);
20 ret
= sched_setaffinity(getpid(), sizeof(cpu_bitmask
),
23 panic("Can't set this cpu affinity!\n");
26 int set_proc_prio(int priority
)
28 int ret
= setpriority(PRIO_PROCESS
, getpid(), priority
);
30 panic("Can't set nice val to %i!\n", priority
);
35 int set_sched_status(int policy
, int priority
)
37 int ret
, min_prio
, max_prio
;
38 struct sched_param sp
;
40 max_prio
= sched_get_priority_max(policy
);
41 min_prio
= sched_get_priority_min(policy
);
43 if (max_prio
== -1 || min_prio
== -1)
44 printf("Cannot determine scheduler prio limits!\n");
45 else if (priority
< min_prio
)
47 else if (priority
> max_prio
)
50 memset(&sp
, 0, sizeof(sp
));
51 sp
.sched_priority
= priority
;
53 ret
= sched_setscheduler(getpid(), policy
, &sp
);
55 printf("Cannot set scheduler policy!\n");
59 ret
= sched_setparam(getpid(), &sp
);
61 printf("Cannot set scheduler prio!\n");
68 ssize_t
proc_get_cmdline(unsigned int pid
, char *cmdline
, size_t len
)
73 snprintf(path
, sizeof(path
), "/proc/%u/exe", pid
);
74 ret
= readlink(path
, cmdline
, len
- 1);