#Why this matters
Files and permissions on disk only describe what could run; live security work depends on knowing what is running right now. Every web server, database, scheduled task, or unexpected backdoor on a Linux host runs in memory as one or more processes.
To diagnose a hung daemon, reduce attack surface, or triage a suspicious connection, you must trace three things together: the running process, its owner account, and the network socket or systemd unit behind it.
#Inspecting running processes
When the Linux kernel boots, it starts the init system as PID 1 (on modern distributions this is systemd), which spawns system services and user sessions. Every process has a numeric Process ID (PID), a Parent PID (PPID), an owner UID, and a state such as R (running or runnable), S (sleeping), or Z (zombie, finished but not yet reaped by its parent).
The ps command reads live kernel process tables exposed under /proc and prints a snapshot. Two classic flag styles appear everywhere:
ps auxshows all users' processes with CPU, memory, state (STAT), start time, and command line.ps -efshowsUID,PID,PPID, and full command, making parent-child chains easy to follow.
$ ps -eo pid,ppid,user:12,stat,cmd --sort=-%cpu | head -n 6
PID PPID USER STAT CMD
1842 1801 www-data S python3 -m http.server 8088
914 1 root Ss sshd: /usr/sbin/sshd -D
880 1 postgres Ss /usr/lib/postgresql/15/bin/postgres
612 1 root Ss /lib/systemd/systemd-journaldNotice how sshd and postgres have PPID 1 because systemd launched them directly, while python3 has PPID 1801 and runs as www-data. Checking the parent process (ps -fp 1801) tells you whether a shell, cron job, or compromised web worker started it.
#Sending signals cleanly
A signal is a lightweight software notification delivered to a process. Administrators use kill (which sends a signal despite its name) to ask a daemon to reload its config or shut down gracefully before forcing termination.
| Signal | Number | Default action | Common use |
|---|---|---|---|
SIGHUP |
1 |
Terminate (often caught to reload) | Reload daemon configuration without dropping connections |
SIGINT |
2 |
Terminate | Interrupt from keyboard (Ctrl+C) |
SIGKILL |
9 |
Force terminate immediately | Last resort when a process ignores SIGTERM |
SIGTERM |
15 |
Terminate gracefully | Default signal sent by kill <pid> |
Always try SIGTERM (kill 1842 or kill -15 1842) before SIGKILL (kill -9 1842). Applications can catch SIGTERM to flush buffers, close files, and remove lock files. The kernel handles SIGKILL directly, so a process cannot catch it, risking corrupted state.
#Managing services with systemd
Long-running background processes (daemons) are normally defined as .service unit files in /lib/systemd/system/ (or /usr/lib/systemd/system/) with local overrides in /etc/systemd/system/. You manage them with systemctl.
Keep runtime state separate from boot persistence:
sudo systemctl start nginx/stop nginx: starts or stops the service right now.sudo systemctl restart nginx: stops and starts it;reloadasks it to re-read configuration if supported.sudo systemctl enable nginx/disable nginx: creates or removes symlinks so the service does or does not launch automatically at boot.systemctl status nginx: shows whether the unit is active, its main PID, recent log lines, and whether it is enabled.
- List socketssudo ss -tulpn
- Trace PIDps -fp PID
- Check unitsystemctl status UNIT
- Act safelystop/disable or reload
#Mapping processes to listening ports
A process listening on a network port expands the host's attack surface. Use ss (socket statistics) with -tulpn to audit open listeners:
-t/-u: show TCP and UDP sockets.-l: show only listening sockets.-p: display the owning process name and PID (requiressudoto see processes owned by other users).-n: show numeric IP addresses and ports instead of resolving names.
$ sudo ss -tulpn
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 127.0.0.1:5432 0.0.0.0:* users:(("postgres",pid=880,fd=5))
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=914,fd=3))
tcp LISTEN 0 5 0.0.0.0:8088 0.0.0.0:* users:(("python3",pid=1842,fd=3))Compare the local addresses: postgres binds to 127.0.0.1:5432 (reachable only from the machine itself), whereas python3 binds to 0.0.0.0:8088 (reachable on every network interface).
#Common mistakes
- Jumping straight to
kill -9: UsingSIGKILLfirst skips graceful cleanup and can corrupt active writes or leave stale PID files. - Stopping without disabling: Running
systemctl stopleaves an unwanted service configured to return after the next reboot unless you also runsystemctl disable. - Omitting
sudowithss -tulpn: Without elevated privileges,ssstill lists ports, but theProcesscolumn stays blank for other users' daemons. - Ignoring bind addresses: Assuming a port is internal when it actually listens on
0.0.0.0exposes internal tools to the wider network.
#Summary
Every running program on Linux is a process with a PID, parent PID, and owner, inspected with ps and controlled through signals such as SIGTERM (graceful) and SIGKILL (forced). Persistent daemons are managed as systemd units via systemctl, where runtime state (start/stop) is distinct from boot persistence (enable/disable). Combining sudo ss -tulpn with ps and systemctl status lets you connect any open port back to its owning process and account.