3

I'm developing an app which will periodically download files from a remote server for a user. I'm wondering whether I should, in OS X parlance, use a daemon, i.e. it will run as long as OS X has been started, or a user agent, i.e. it will run as long as the particular user is logged in. Is there a convention? Are there any rules to abide by when thinking about this? I certainly don't want buck convention and end up having my app do something a user isn't expecting it to do.

Also, for such background processes, it seems like there might be a convention to have the app show up on the status bar. E.g. both Google drive and Mozy on my machine, which monitor for changes and upload in the background, both are represented in the status bar. Is this something I should do with my app?

pkamb
  • 26,648
  • 20
  • 124
  • 157
pondermatic
  • 6,147
  • 8
  • 44
  • 57

2 Answers2

3

there is absolutely a convention, a daemon is typically run as root or a special user (mysql, www), and a Agent runs as the user...

it doesn't matter with respect to how long they may live etc, as a daemon can either be long running like httpd, ftpd, etc, or launched just in time for use, as in a helper tool.

from man launchd:

In the launchd lexicon, a "daemon" is, by definition, a system-wide service of which there is one instance for all clients. An "agent" is a service that runs on a per-user basis. Daemons should not attempt to display UI or interact directly with a user's login session. Any and all work that involves interacting with a user should be done through agents.

so you may mix with some sort of IPC as in a backup daemon may send messages to a status bar app, which runs as and agent for your user.

AlvaroAV
  • 9,087
  • 10
  • 52
  • 83
Grady Player
  • 13,550
  • 2
  • 47
  • 75
1

Daemon vs Agent

UNIX Daemon - program(.plist + binary) which is running as a background process(like service in Windows)

Daemon is a UNIX Daemon without GUI. launchd starts it when a system has started(behalf on root). *launchd is also daemon - pid is 1 ant it creates all other processes. Usually daemons have -d suffix(e.g. launchd, nsurlsessiond[About]). For example daemons can be used for Printer, Bluetooth...

Agent - is a UNIX daemon which can work with GUI through window server. launchd starts agent behalf on user after login with defined user permissions. For example Calendar, Skype...

launchd knows about daemons based on .plist in

User Agents     ~/Library/LaunchAgents         specific user
Global Agents   /Library/LaunchAgents          all users
System Agents   /System/Library/LaunchAgents   MacOS

Global Daemons  /Library/LaunchDaemon          installed apps
System Daemons  /System/Library/LaunchDaemons  MacOS

[Java Daemon tread]

yoAlex5
  • 13,571
  • 5
  • 105
  • 98