I am confused by the fact that there seem to be two different
priorities in the kernel: the BSD process priority (sysctl
API) and
the Mach task priority (proc_taskinfo
API).
I hate to add to your confusion but the latter is not a Mach API. Rather, it’s from libproc, which is not a BSD API but has more of a BSD flavour to it.
The Mach APIs are in the usr/include/mach
area of the SDK, and you want to look at host_info
, task_info
, and thread_info
. Each of these takes a ‘flavour’ parameter that describes the specific info you’re looking for. What I generally do here is:
-
Look up the docs for the specific API.
-
Discover one of the flavour values from that.
-
Find that in the headers.
-
And then look for other interesting flavours nearby.
For example, you can find the docs for task_info
here, which lists the TASK_BASIC_INFO
flavour, which is declared in <mach/task_info.h>
, which leads to other fun flavours like TASK_EVENTS_INFO
.
Taking a step back, be very careful with Mach APIs. They are supported, but only just. If there is a higher level equivalent, use that. So, for example, prefer Swift concurrency over NSThread
over pthreads over Mach threads.
Your high-level goal seems to be analytics, and that’s one place where it’s pretty reasonable to use Mach APIs. It’d be best if you disabled those on production releases to limit your binary compatibility exposure, but I can understand why you might not want to do that.
One thing to avoid is basing runtime decisions on values returned by Mach APIs. I regularly see folks try to do this, and it generally doesn’t end well. For a specific example, see On Free Memory.
Oh, and this general queasiness about Mach APIs is one of the reasons that we don’t publish docs for them in the standard doc library. The only place we publish docs is in the kernel source code, starting here.
Oh, and I have at least two book recommendations for you:
Both are super old but they’ll give you some historical background on how this stuff fits together.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"