I have a system extension which contains 3 capabilities: App Proxy, Content Filter, Packet Tunnel.
System extension process doesn't auto stops on disabling all of its Capabilities: App Proxy, Content Filter, Packet Tunnel
How to make system extension process auto stop if all of its capabilities disabled? Disable can happens via system extension hosting app or system preference network settings
I have following in mind:
Whenever we disables any capabilities via system extension hosting app, it can check if all others are disabled then
- Use KILL bash command to terminate system extension process
- System extension hosting app can send message via XPC to extension to terminate it self via NSApp.terminate
- On disabling from system preference, ssystem extensions can check if all other disables in delegate method and terminate itself
I wanted to know what is better way to handle system extension process stop
A system extension is roughly equivalent to a launchd
daemon, and launchd
uses an on-demand lifecycle. That is:
-
It starts the daemon when something needs its services.
-
The daemon becomse eligible for termination when there’s no work in flight. In the case of an NE sysex, this happens when the last provider stops.
Note the use of the term eligible in that second point. The system won’t necessarily terminate a daemon in that case. Rather, it starts terminating daemons when it comes under memory pressure. This is a significant performance optimisation, allowing it to use otherwise ‘free’ memory [1] to cache the state of inactive daemons.
Given that model, the best thing for you to do is… well… nothing. Just let the system do its thing.
Oh, there is one thing that you should do, namely to check that your sysex goes completely idle when all your providers stop. That is:
-
Try to release as much memory as you can.
-
Make sure that nothing is causing code to run unnecessarily, like timers or notification handlers.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] On a system that uses virtual memory, there’s really no such thing as free memory. I discuss this in detail in On Free Memory.