I found that the launchd
process has multiple instances in the process list. What is looking interesting is that there are four users under which these launchd
processes are running:
- root
- < current_user[i.e. me] >
- _windowserver
- _spotlight
As described in Apple's docs (Creating Launch Daemons and Agents), launchd
will be launched per user. But why are the users which requires launchd
such as _spotlight
and _windowserver
. I would expect only root
and <current_user[i.e. me]>
. Why both users (_spotlight
and _windowserver
) require the launchd? I would appreciate for any references to Apple docs or any other resources.
the process parent-child relations are as following:
kernel_task(0,root) -> launchd(1,root) -> launchd(130, _windowserver)
-> launchd(150, <current_user[i.e. me]>)
-> launchd(470, _spotlight)
Best Answer
The clear answer is that by separating processes into users, you separate the permissions that each process inherits. This is a long standing unix idiom for security and control of resources by placing per user limits on things like open files and memory and even threads/processes.
On OS X - spotlight needs to spawn processes to index files, window server is responsible for bringing up the lock screen, and things to prepare for the first graphical user to log in. Root is the defacto admin account with broad levels of power and permissions. Each user process gets a launchd to start the programs and things they need.
As far as official documentation, I'd start with this article on Daemons and Services.
https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/Introduction.html
It shows the user vs system level split already in the first page. You can search for other launchd topics from that link if needed (or use Xcode to browse the documentation offline).