Development osx deamon which runs before user login with xcode

Hi I am trying to create a daemon using objective-C / xcode.

I am new to the mac world and can I get an idea of โ€‹โ€‹which project template to choose in xcode and how to do it.

Can I get a simple and basic source code for the sample daemon?

+2


source to share


1 answer


The Command Tool project is enough to start creating a daemon. No special build requirements per se, it just depends on what you want the daemon to do.

The way you write the Mac OS X daemon is very similar to how you would approach it on a regular Unix system. Accordingly, there are several things to keep in mind:

  • non-interactive : you don't get direct input from the user, but you should also use something like syslogd

    for output, since the process is not connected to the terminal li>
  • environment : don't assume it has a specific current directory, path, default permissions or any other environment settings - set these explicitly
  • security : make sure that the daemon has the minimum minimum privileges required to perform its function and no more (this is a huge topic in itself).
  • signals : you will need to monitor and respond to certain signals as they are commonly used to control a process (for example, SIGHUP

    forcing the daemon to reload its config file)

There is some good entry on Unix daemons if you take a look. Stevens' book on Unix is โ€‹โ€‹always good.



There is some Mac specific information about daemons , mainly for integration with launchd

.

A typical daemon will do something like the following:

  • double-fork to detach from the parent process
  • configure process group and effective UID
  • install signal handlers
  • set file permissions umask
  • change directory to working directory
  • read config file
  • open sockets, etc.
  • go into an infinite loop to serve requests

The Wikipedia article has an example of a simple daemon .

+4


source







All Articles