On Linux, sched.h
contains the definition of
int sched_rr_get_interval(pid_t pid, struct timespec * tp);
to get the time slice of a process. However the file shipping with OS X El Capitan doesn't hold that definition.
Is there an alternative for this on OS X?
The API's related to this stuff are pretty byzantine and poorly documented, but here's what I've found.
First, the datatypes related to RR scheduling seem to be in /usr/include/mach/policy.h
, around line 155. There's this struct:
struct policy_rr_info {
...
integer_t quantum;
....
};
The quantum
is, I think, the timeslice (not sure of units.) Then grepping around for this or related types defined in the same place, I found the file /usr/include/mach/mach_types.def
, which says that the type struct thread_policy_t
contains a field policy_rr_info_t
on line 203.
Next, I found in /usr/include/mach/thread_act.h
the public function thread_policy_get
, which can retrieve information about a thread's policy into a struct thread_policy_t *
.
So, working backwards. I think (but haven't tried at all) that you can
thread_policy_get()
routine to return information about the thread's scheduling state into a thread_policy_t
policy_rr_info_t
sub-substructurequantum
field.There are no man pages for this part of the API, but this Apple Developer page explains at least a little bit about how to use this API.
Note that this is all gleaned from just grepping the various kernel headers, and I've definitely not tried to use any of these APIs in any actual code.