Mach provides a small number of primitives for managing processes. Most of these are done by sending messages to the kernel via the process port, rather than actual system calls. The most important of these calls are shown in Fig. 8-3. These, like all calls in Mach, have prefixes indicating the group they belong to, but we have omitted these here (and in subsequent tables) for the sake of brevity. Fig. 8-3. Selected process management calls in Mach. The first two calls in Fig. 8-3 are for creating and destroying processes, respectively. The process creation call specifies a prototype process, not necessarily the caller. The child is a copy of the prototype, except that the call has a parameter that tells whether or not the child is to inherit the parent's address space. If it does not inherit the parent's address space, objects (e.g., text, initialized data, and a stack) can be mapped in later. Initially, the child has no threads. It does, however, automatically get a process port, a bootstrap port, and an exception port. Other ports are not inherited automatically since each port may have only one reader. Processes can be suspended and resumed under program control. Each process has a counter, incremented by the suspend call and decremented by the resume call, that can block or unblock it. When the counter is 0, the process is able to run. When it is positive, it is suspended. Having a counter is more general than just having a bit, and helps avoid race conditions. The priority and assign calls give the programmer control over how and where its threads run on multiprocessor systems. CPU scheduling is done using priorities, so the programmer has fine-grain control over which threads are most important and which are least important. The assign call makes it possible to control which thread runs on which CPU or group of CPUs. The last two calls of Fig. 8-3 return information about the process. The former gives statistical information and the latter returns a list of all the threads.Process Management Primitives
Call
Description
Create
Create a new process, inheriting certain properties
Terminate
Kill a specified process
Suspend
Increment suspend counter
Resume
Decrement suspend counter. If it is 0, unblock the process
Priority
Set the priority for current or future threads
Assign
Tell which processor new threads should run on
Info
Return information about execution time, memory usage, etc.
Threads
Return a list of the process' threads