dEEpEst
☣☣ In The Depths ☣☣
Staff member
Administrator
Super Moderator
Hacker
Specter
Crawler
Shadow
- Joined
- Mar 29, 2018
- Messages
- 13,861
- Solutions
- 4
- Reputation
- 32
- Reaction score
- 45,552
- Points
- 1,813
- Credits
- 55,350
7 Years of Service
56%
Linux Mystery: Disappearing Processes in systemd Services

Disclaimer: This topic is intended for educational and debugging purposes in secure environments. Misconfiguration in service units can lead to unexpected behavior or vulnerabilities.

You're running a daemon (e.g.,
mydaemon
) on Ubuntu 22.04, started via a systemd unit. systemctl status mydaemon
says it’s active (running), yet:ps aux | grep mydaemon
shows nothingtop
,htop
,pgrep
,pidof
return no matches
But restarting it with
systemctl restart mydaemon
logs a clean start — no errors. Still no visible process.
- Check the unit type:
INI:Type=simple ExecStart=/bin/bash -c 'sleep 9999'
- Run:
Bash:systemctl show -p MainPID mydaemon
MainPID=0
or a PID that vanishes quickly. - Why? With
Type=simple
, systemd assumes the parent process launched by ExecStart is the main one — in this case,bash
. Butbash -c 'sleep 9999'
spawnssleep
and exits, leaving systemd tracking a non-existent PID.

- Avoid shell wrappers:
Instead of usingbash -c
, directly run the binary:
INI:ExecStart=/usr/bin/sleep 9999
- Use
Type=forking
(if your daemon forks itself) and define aPIDFile
:
INI:Type=forking PIDFile=/var/run/mydaemon.pid ExecStart=/usr/bin/mydaemon
- Use
Type=exec
(available in systemd v240+), which tracks the last process in the chain:
INI:Type=exec ExecStart=/bin/bash -c 'sleep 9999'
- Use
Type=notify
if the daemon supportssd_notify
:
INI:Type=notify ExecStart=/usr/bin/mydaemon --notify-ready

- Check
MainPID
:
Bash:systemctl show -p MainPID mydaemon
- Inspect running processes and hierarchy:
Bash:ps -eo pid,ppid,cmd | grep mydaemon
- Redirect logs to a file for more clarity:
INI:StandardOutput=file:/var/log/mydaemon.log StandardError=file:/var/log/mydaemon.err
