What is a daemon process?
Why Interviewers Ask This
This question targets practical, hands-on experience with Operating Systems. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
Answer
A daemon is a background process that runs continuously without direct user interaction, providing services to the system or other processes. Daemons typically start at system boot and run until shutdown. Named "daemon" (from Greek mythology — spirits that work in the background). Characteristics of daemons: run in background, not associated with a terminal; typically have no stdin/stdout/stderr (or redirected to /dev/null or log files); usually run as root or a dedicated system user; often have names ending in "d" (httpd, sshd, mysqld, cron, syslogd); started by system startup scripts (systemd, init.d). Common system daemons: sshd (SSH server), httpd/nginx (web server), mysqld/postgres (database), crond (scheduled tasks — cron jobs), syslogd/rsyslogd (system logging), udevd (device management), networkd (networking), journald (systemd logging). Creating a daemon (Unix): (1) fork() and parent exits (orphans the child, shell gets prompt back); (2) child calls setsid() (creates new session, detaches from terminal); (3) fork() again (prevents daemon from opening a terminal); (4) Change working directory to / (avoid preventing unmounts); (5) Close standard file descriptors (0, 1, 2); (6) Open /dev/null for stdin; redirect stdout/stderr to log file or /dev/null; (7) Run daemon logic. systemd unit files (modern): [Service] Type=forking ExecStart=/usr/bin/myapp Restart=always. Systemd handles daemonization automatically.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.