MAC OSX Agents - how to launch multiple instances
Asked Answered
A

2

0

I am trying to create helper objects (it could be a daemon or an agent). This should be launch on demand and its multiple instances should be there, as you see for Chrome and Safari helpers.

What Have I tried? I have referred these Apple Docs, Launchd Tutorial & Creating Start Up Items in Mac OS X

There it is mentioned that for number of processes we should use NumberOfProcesses key, I used it but in Activity Monitor I see only one instance.

And my plist looks like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.anoop.test</string>
    <key>NumberOfProcesses</key>
    <string>5</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/anoopvaidya/Desktop/0@/WebTwainService</string>
        <string>start</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>Application is agent (UIElement)</key>
    <string>YES</string>
</dict>
</plist>

Am I on correct path to replicate Launch Agent Helper as of Chrome? Please help me to find the best way to get it done?

Aten answered 16/4, 2015 at 16:21 Comment(0)
N
2

NumberOfProcesses is not a top-level key. It's a sub-key of HardResourceLimits, and it's used to indicate how many sub-processes your daemon or agent may create before the kernel stops you. It has nothing to do with launchd creating multiple instances of your process.

Launchd does not support managing multiple processes for a single job. Chrome and Safari do not use Launchd to manage their job processes. They manage these themselves.

If you want a separate process per application being helped, then you can achieve that with an Application XPC Service, but XPC also does not support multiple processes for a service that is assisting a single application. See Running multiple instances of the same XPC service (NSXPCConnection) for more.

The typical pattern is to have a single LaunchAgent/Daemon that accepts incoming connections, and then forks itself to handle each client independently. I assume the same pattern should work for XPC Services (which are now preferred), but I haven't built one that way before.

Nasturtium answered 16/4, 2015 at 17:46 Comment(1)
Thanks for showing me the path. So here I need to fork. I will try using this link #2708072Aten
S
0

Seems there is top-level boolean key MultipleInstances (seen on macOS 14.1)

For example, check /System/Library/LaunchDaemons/com.apple.DesktopServicesHelper.plist

Scrupulous answered 29/2 at 12:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.