Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple instances of the same XPC service (NSXPCConnection)

Is it possible to run multiple instances of the same XPC service using the XPC APIs found in Foundation.framework (NSXPCConnection, etc.)? The docs don't provide much insight on this matter.

EDIT: Did a quick test, and it seems like only one instance of the service is running even though I created two XPC connections. Is there any way to have it run another instance?

like image 845
indragie Avatar asked Dec 26 '12 03:12

indragie


People also ask

What is XPC services on Iphone?

The XPC Services API provides a lightweight mechanism for basic interprocess communication at the libSystem level. It allows you to create lightweight helper tools, called XPC services, that perform work on behalf of your app.

What is XPC service on Mac?

macOS uses XPC services for basic inter-process communication between various processes, such as between the XPC Service daemon and third-party application privileged helper tools.

What is a daemon Swift?

Daemons are strictly background processes that respond to low-level requests. Most daemons run in the system context of the system—that is, they run at the lowest level of the system and make their services available to all user sessions.


2 Answers

A bit late, but the definitive answer to this question is provided in the xpcservice.plist manpage:

ServiceType (default: Application)

The type of the XPC Service specifies how the service is instantiated. The values are:

• Application: Each application will have a unique instance of this service.

• User: There is one instance of the service process created for each user.

• System: There is one instance of the service process for the whole system. System XPC Services are restricted to reside in system frameworks and must be owned by root.

Bottom line: In most cases there is a single instance of an XPC Service and only in the case where different applications can connect to the same service (not even possible when the service is bundled with an app), will there be multiple instances (one-instance-per-app).

like image 143
trojanfoe Avatar answered Nov 15 '22 19:11

trojanfoe


I believe XPC services designed for one instance per multiple connections. Probably, it is more convenient to manage named pipes with one running executable. So, the most likely it is impossible to create multiple instances simultaneously.

like image 32
Vadim Avatar answered Nov 15 '22 19:11

Vadim