Linux: Processes, Services and Software
A Linux system isn’t just files: it’s what’s running. Which processes exist, under which user, which services start by themselves and what cron runs every minute is exactly what you look for when enumerating a compromised machine, because that’s where the privileged programs you can hijack show up. And on your own Kali, knowing how to control processes, services and installs saves you hours of “it doesn’t work and I don’t know why”.
Concepts
Section titled “Concepts”Processes
Section titled “Processes”- A process is a running program. It has a PID, a PPID (the process that launched it) and runs with the user and permissions of whoever started it.
/proc/<pid>/exposes its live information:cmdline(the arguments it was launched with),environ(its environment variables, if you have permission) andcwd(its directory).
| Command | What it shows |
|---|---|
ps aux |
Snapshot of every process, with user, PID and command |
ps -ef --forest |
Process tree: who launched whom |
top · htop |
Live view of CPU and memory usage |
pgrep -a name |
PID and command of matching processes |
Signals
Section titled “Signals”| Signal | Number | How it’s sent | Effect |
|---|---|---|---|
| SIGTERM | 15 | kill PID (default) |
Asks it to terminate cleanly |
| SIGKILL | 9 | kill -9 PID |
Immediate stop, no cleanup. Last resort |
| SIGINT | 2 | Ctrl+C |
Interrupt from the terminal |
| SIGTSTP | 20 | Ctrl+Z |
Pause and hand control back to the shell |
| SIGHUP | 1 | Closing the terminal | The process usually dies; many daemons use it to reload config |
Foreground and background
Section titled “Foreground and background”nmap -p- 10.10.10.5 -oN all.txt & # run in the backgroundjobs # this shell's jobsfg %1 # bring job 1 to the foreground# Ctrl+Z pauses the current one; bg keeps it running in the backgroundnohup ./script.sh > out.log 2>&1 & # survive closing the terminalServices and systemd
Section titled “Services and systemd”A daemon is a process without a terminal that waits to be needed (sshd, nginx, cron). systemd starts them, watches them and restarts them; each is defined in a unit (/etc/systemd/system/*.service or /lib/systemd/system/).
| Command | What it does |
|---|---|
systemctl status ssh |
State, PID and the last log lines |
systemctl start ssh · stop · restart |
Start, stop, restart now |
systemctl enable ssh · disable |
Start it at boot (or not). Doesn’t start it now |
systemctl enable --now ssh |
Both at once |
systemctl list-units --type=service --state=running |
Running services |
journalctl -u ssh -f |
The service’s full log, live |
The classic logs are still in /var/log (auth.log or secure for authentication, syslog or messages for the system).
Scheduled tasks
Section titled “Scheduled tasks”- cron:
/etc/crontab,/etc/cron.d/,/etc/cron.{hourly,daily,weekly}/and each user’s crontab (crontab -l). Each line: minute, hour, day of month, month, day of week, (user) and command. - systemd timers:
systemctl list-timers.
tmux: sessions you don’t lose
Section titled “tmux: sessions you don’t lose”tmux keeps your sessions alive even if you close the terminal or the SSH or VPN connection drops; they only die if the machine they run on reboots. It also lets you split the screen to have a listener, a scan and your shell side by side.
| Action | Keys or command |
|---|---|
| New named session | tmux new -s lab |
| Detach · reattach | Ctrl+b d · tmux a -t lab |
| List sessions | tmux ls |
| New window · next | Ctrl+b c · Ctrl+b n |
| Split vertically · horizontally | Ctrl+b % · Ctrl+b " |
| Move between panes · close | Ctrl+b + arrow · Ctrl+b x |
Installing software
Section titled “Installing software”In order of preference: the package manager, the language’s package manager and, as a last resort, building or downloading by hand.
| Route | Command | Where it ends up | Notes |
|---|---|---|---|
| System packages | sudo apt update && sudo apt install nmap |
/usr/bin |
Resolves dependencies. dpkg -i file.deb installs a standalone .deb without resolving them |
| Python tools | pipx install tool |
~/.local/bin |
Each tool in its own isolated environment |
| Python projects | python3 -m venv .venv && . .venv/bin/activate && pip install -r requirements.txt |
Inside .venv |
For code you clone and run |
| Go | go install github.com/author/tool@latest |
~/go/bin |
That directory isn’t in the PATH by default |
| Source code | git clone https://… |
Wherever you clone it | Cloning isn’t installing: the system doesn’t know it exists |
| By hand | Downloaded binary | /usr/local/bin or /opt |
Check where you download it from |
In practice
Section titled “In practice”# What runs as root?ps aux | awk '$1=="root"' | grep -vE '\[|ps aux'
# Which services listen, and with which process?sudo ss -tlnp
# A service that won't start, in this ordersystemctl status nginxjournalctl -u nginx -n 50 --no-pagersudo ss -tlnp | grep ':80 ' # is another process already on the port?
# Visible scheduled taskscat /etc/crontab; ls -la /etc/cron.*; crontab -l 2>/dev/nullsystemctl list-timers --allNext offensive step
Section titled “Next offensive step”- Enumerate processes, services and tasks on a compromised machine: Linux enumeration.
- Abuse scheduled tasks: cron.
- Stay on the system with your own services and tasks: Linux persistence.
Cheat sheet
Section titled “Cheat sheet”| Concept | What to remember |
|---|---|
| Process | PID, PPID and the permissions of whoever launched it. |
/proc/<pid>/cmdline · environ |
Arguments and variables: sometimes with passwords. |
kill · kill -9 |
Asks to terminate (15) · hard stop (9). |
& · Ctrl+Z · bg · fg |
Background · pause · continue behind · bring forward. |
nohup · tmux |
Survive closing the terminal · persistent sessions. |
start · enable |
Now · at boot. Both: enable --now. |
journalctl -u service |
The service’s log. |
| cron | /etc/crontab, /etc/cron.*, crontab -l. |
apt update |
Always before installing. |
externally-managed-environment |
Use pipx or venv. |
go install |
Ends up in ~/go/bin: add it to the PATH. |
Review questions
Section titled “Review questions”-
What’s the difference between
systemctl startandsystemctl enable?Answer
startstarts the service now, but it won’t start on the next boot.enableconfigures it to start at boot, but doesn’t start it now.enable --nowdoes both. -
A process doesn’t respond to
kill PID. What do you do, and what’s the risk?Answer
kill -9 PID, which sends SIGKILL and stops it without letting it clean up: it can leave temporary files, locks or half-written data behind. -
You start a long scan over SSH and the connection drops. How could you have avoided losing it?
Answer
By running it inside tmux (or with
nohupin the background): the process stays alive on the machine even if the session closes, and with tmux you can reattach. -
On a compromised machine you see a root process running
/opt/scripts/backup.shevery minute, and the file is writable by your user. What does that mean?Answer
That you can add commands to the script and they’ll run as root on the next execution: it’s a privilege escalation.
-
pip install toolfails withexternally-managed-environment. What do you do?Answer
Install it with
pipx(if it’s a command-line tool) or inside a virtual environment created withpython3 -m venv. Don’t force the install into the system Python. -
Why is
/proc/<pid>/environinteresting when enumerating?Answer
Because it holds the environment variables the process was launched with, and many applications receive credentials or keys there. You can only read it for your own user’s processes (or all of them if you’re root).