Agents and Daemons

Changsin Lee
6 min readApr 1, 2024

What are agents and daemons in macOS? How can you create them?

Photo by Diane Picchiottino on Unsplash

In computer science, a daemon is a background process that does not directly interact with the user. According to the Wikipedia definition, it is not related to a Satanic being but came from Greek mythology where a daemon is a second-tier deity who works in the background.

In Unix-like systems including macOS, a daemon is a system process launched and managed by a super-server daemon like launchd. In this article, I want to explain what it takes to make a daemon process in macOS through an example.

An example service

For illustration purposes, here is a sample local web service written in Python. Here is the code snippet.

import json
from http.server import SimpleHTTPRequestHandler, HTTPServer


class RequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b"Hello, this is your localhost server.")

The Python script can be compiled into a single executable file through PyInstaller with this command:

pyinstaller -F webserver_sample.py

The resulting executable file ‘webserver_sample’ will be placed under ./dist folder and this is the file we will use.

--

--

Changsin Lee

AI/ML Enthusiast | Software Engineer | ex-Microsoftie | ex-Amazonian