How exactly apps are launched

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

How exactly apps are launched

Postby terran » Tue May 07, 2019 8:31 pm

I tried googling the subject, but couldn't find any info, please point me in the right direction.
I want to know how exactly the apps are launched on macOS/iOS.
Afaik when I run something from the Terminal, the shell gets forked, then there's execve call with the target app path, then magic and voila.
1. What happens when I run an app from Aqua/SpringBoard?
2. Which part of the system will allocate memory for the process and set registers for main?
3. How those parts communicate?
4. How arguments get passed to the app ran this way? And if I tell launchd to run an app by a plist?
Posts: 5
Joined: Fri Mar 08, 2019 10:14 am

Re: How exactly apps are launched

Postby morpheus » Wed May 08, 2019 9:51 am

So, it's actually discussed in Volume I. Springboard/Finder launch through an XPC message to launchd (I forget which now, but it's also shown as a "bonus" in the source of launjctl I posted). This gets launchd to first spawn xpcproxy, which takes the path as an argument, sandboxes itself and then posix_spawns the binary in place (That is, with an undocumented flag which exec()s only, without forking). So how they communicate is over an XPC message). You can follow the launch process (from the BSD perspective, that is just processes but no Mach messages) using supraudit.

Launching an app by a plist is again, in launjctl.c

At any rate, it is the KERNEL which handles the loading of the process.
Site Admin
Posts: 737
Joined: Thu Apr 11, 2013 6:24 pm

Re: How exactly apps are launched

Postby terran » Sat May 11, 2019 11:25 am

I haven't bought any of the new volumes yet - waiting for the colored edition.
Could you please specify which bonus source are you referring to?
I played with ps a bit (from Chapter 7 of the old book) and found out that all of my open GUI applications have PPID same as PID of -bash.
How come? Does it mean that GUI apps are run as shell programs with fork()+execve() calls from some background(?) bash mother process, or I simply misinterpreted the output?
Posts: 5
Joined: Fri Mar 08, 2019 10:14 am

Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 4 guests