How to know if an application was started using launchd

Is there a reliable way to know that an application was started using launchd, and not on command-line or from Finder?

Is there a reliable way to know that an application was started using launchd, and not on command-line or from Finder?

Ah, um, app’s launched from the Finder are launched by launchd:

% ps ajxww                
USER               PID  PPID … COMMAND
root                 1     0 … /sbin/launchd
……
quinn            21683     1 … /System/Applications/TextEdit.app…

The Finder launches apps using high-level APIs (NSWorkspace or, equivalently, Launch Services) and those ultimately pass the work off to launchd [1].

Can you explain more about your goals here? Why do you need to detect how your app was launched?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] On modern systems. Historically this work was done by the window server.

Thanks Quinn ... let me see if I can explain the scenario.

We are building an application, which (in theory) can be run as an interactive application, OR started as a non-interactive 'daemon/agent' - depending on the deployment outcome the end-user would want. For example, on a Windows machine, the same application could be 'started as Service' (in which case, none of the code flows which have UI ever get invoked by us) - OR as an interactive application. That is the same case on MacOS. Unfortunately, I have not been able to determine 'conclusively' how to determine the mode of starting the application, and therefore, ensure that we are not following any of the UI flows. (When run as a daemon, the application interacts with other UI applications either on the same system, or on other network systems, and acts as a data server for them. When run in interactive mode, it not only acts as a data server for other network systems, but also allows the local user to operate the application). Does this help?

For those reading along, I’ll be helping Bharat_Goenka in a different context.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks Quinn. Was I able to explain the scenario/case? When can expect some suggestions/directions? (We did (as an organization) post the same query by buying some TSI credits, and they pointed us back to this forum - so am presently in 'wait' mode for a direction)

they pointed us back to this forum

Hmmm, that’s not my interpretation of what happened. I don’t conduct DTS business here on DevForums, so please drop me a line via email (my address is in my signature) so that we can sort this out in private.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How to know if an application was started using launchd
 
 
Q