Do executables in OS X need to be built in specific way to be used as a service?
Solution 1:
An executable on macOS can be run as a service or application almost regardless of how it is created.
The question to ask is, does the process require access to the WindowServer? The WindowServer is needed to provide a graphical interface.
Graphical User Interface and User Sessions
A process requiring a graphical user interface can be used as a background process or service. Do this by launching the process with launchd
from the /Library/LaunchAgents
folder.
To present a graphical user interface, the process must be launched within a user session. In launchd
terms this means within an Aqua
environment.
An example of this would be Power Manager's pmuser
process. This process manages tasks specific to the user and handles tasks that the computer wide pmd
process can not directly perform.
Computer Wide Processes
A process that does not require a user interface can be launched as a background service with launchd
from the /Library/LaunchDaemons
folder.
A non-graphical process can exist outside of any user session and thus run even when no-one is logged in.
A computer wide process can not access much of macOS's unique functionality. See Apple's TechNote 2083 and the Living Dangerously section.