launchd:launchd can launch daemons that run continuously,inetd for launching inetd-style daemons.launchd can start jobs at timed intervals.launchd supports non-launch-on-demand daemons, this use is not recommended. The launchd daemon was designed to remove the need for dependency ordering among daemons. If you do not make your daemon be launched on demand, you will have to handle these dependencies in another way, such as by using the legacy startup item mechanism.launchd in OS X v10.4, an effort was made to improve the steps needed to launch and maintain daemons. What launchd provides is a harness for launching your daemon as needed. To client programs, the port representing your daemon’s service is always available and ready to handle requests. In reality, the daemon may or may not be running. When a client sends a request to the port, launchd may have to launch the daemon so that it can handle the request. Once launched, the daemon can continue running or shut itself down to free up the memory and resources it holds. If a daemon shuts itself down, launchd once again relaunches it as needed to process requests.In addition to the launch-on-demand feature, launchd provides the following benefits to daemon developers:
Simplifies the process of making a daemon by handling many of the standard housekeeping chores normally associated with launching a daemon.
Provides system administrators with a central place to manage daemons on the system.
Supports inetd-style daemons.
Eliminates the primary reason for running daemons as root. Because launchd runs as root, it can create low-numbered TCP/IP listen sockets and hand them off to the daemon.
Simplifies error handling and dependency management for inter-daemon communication. Because daemons launch on demand, communication requests do not fail if the daemon is not launched. They are simply delayed until the daemon can launch and process them.
Launchd的配置文件
/Library/LaunchDaemons, and those describing agents are installed in /Library/LaunchAgents or in the LaunchAgents subdirectory of an individual user’s Library directory. (The appropriate location for executables that you launch from your job is /usr/local/libexec.)|
Key |
Description |
|---|---|
|
|
Contains a unique string that identifies your daemon to |
|
|
Contains the arguments used to launch your daemon. (required) |
|
|
Indicates that your daemon requires a separate instance per incoming connection. This causes |
|
|
This key specifies whether your daemon launches on-demand or must always be running. It is recommended that you design your daemon to be launched on-demand. |
launchd takes care of dependencies between daemons, in some cases, your daemon may depend on other system functionality that cannot be addressed in this manner. This section describes many of these special cases and how to handle them.launchd daemon, you must take additional care to ensure that your daemon works correctly if that non-launchd daemon has not started when your daemon is started. The best way to do this is to include a loop at start time that checks to see if the non-launchd daemon is running, and if not, sleeps for several seconds before checking again.SIGTERM prior to this loop to ensure that you are able to properly shut down if the daemon you rely on never becomes available.原文:http://www.cnblogs.com/andypeker/p/4362239.html