GO KALI FREE
BeginnerLinux

Linux Process Management: Monitoring and Controlling Processes

Learn to manage Linux processes effectively including monitoring tools, signals, priority control, background jobs, and automation with systemd.

#process management#Linux#systemd#signals#monitoring

Controlling Processes in Linux

When a system is compromised, malicious processes hide among legitimate ones. Knowing how to inspect, prioritize, and terminate processes gives you the ability to identify anomalies, stop attacks in progress, and keep your own tools running efficiently. This guide covers the practical skills you need to manage processes from the command line.

Prerequisites

Basic Linux command line knowledge. Familiarity with ps and top commands.

Process States

StateCodeDescription
RunningRCurrently executing or in run queue
SleepingSWaiting for an event (interruptible)
Uninterruptible SleepDWaiting for I/O
StoppedTPaused by a signal
ZombieZTerminated but not cleaned up by parent

Viewing Processes

ps — Process Snapshot

ps aux                          # All processes with details
ps ux                           # Current user's processes
ps auxf                         # Process tree
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -10  # Sort by memory

Output columns: USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND.

top — Dynamic Process Viewer

top

Interactive keys: P (sort by CPU), M (sort by memory), k (kill process), u (filter by user), q (quit).

htop — Enhanced Viewer

sudo apt install htop
htop

Color-coded, mouse support, easier process management. For advanced navigation keys, custom meter meters, and process tree viewing, consult our in-depth htop command reference.

Process Signals

kill -1 PID     # SIGHUP - Reload configuration
kill -2 PID     # SIGINT - Interrupt (Ctrl+C)
kill -9 PID     # SIGKILL - Force kill (cannot be ignored)
kill -15 PID    # SIGTERM - Terminate gracefully (default)
kill -19 PID    # SIGSTOP - Pause
kill -18 PID    # SIGCONT - Resume

Sending Signals

kill -15 1234                  # Kill by PID
pkill -9 firefox               # Kill by name
killall -15 chrome             # Kill by name pattern
pkill -u username              # Kill all processes for a user
timeout 5 tail -f /var/log/syslog  # Kill after timeout

To search processes by name and send targeted termination signals without looking up individual PIDs, explore our comprehensive guides for killall, pkill, and pattern searching with pgrep.

Always try SIGTERM (15) first — allows clean shutdown. Use SIGKILL (9) only when a process does not respond.

Process Priority (Nice Values)

Values range from -20 (highest priority) to 19 (lowest).

nice -n 10 ./backup_script.sh     # Start with lower priority
renice -n -5 -p 1234              # Change priority of running process (root only)
ps -eo pid,ni,cmd | sort -k2      # View priorities

For scheduling priority adjustment and Completely Fair Scheduler (CFS) behavior, see our detailed technical guides on starting processes with nice and adjusting running processes with renice.

Background and Foreground Jobs

nmap -sV 192.168.1.1 &            # Run in background
# Ctrl+Z suspends current foreground job
jobs                               # List background jobs
fg %1                              # Bring job to foreground
bg %1                              # Send to background
nohup ./long_script.sh &           # Continue after logout
disown %1                          # Remove from job table

For mastering interactive shell job control and session decoupling, read our dedicated references on monitoring active shell tasks with jobs, bringing tasks forward with fg, backgrounding paused jobs with bg, and immunity to SIGHUP terminal disconnections with nohup.

systemd Service Management

systemctl list-units --type=service    # List all services
systemctl status ssh                   # Check service status
sudo systemctl start ssh               # Start a service
sudo systemctl stop ssh                # Stop a service
sudo systemctl restart ssh             # Restart a service
sudo systemctl enable ssh              # Enable at boot
sudo systemctl disable ssh             # Disable at boot
journalctl -u ssh                      # View service logs
journalctl -u ssh -f                   # Follow service logs

For comprehensive administration guides on managing service lifecycles, explore starting services with systemctl start, stopping daemons with systemctl stop, restarting processes with systemctl restart, configuring boot persistence with systemctl enable, and disabling automated startup with systemctl disable. To monitor running status, cgroup resource utilization, and recent log outputs, see systemctl status, and to inspect loaded systemd units across the operating system, consult systemctl list-units. For compatibility with legacy SysV init scripts, see our service reference, and for structured querying of systemd journal logs, explore journalctl.

Monitoring Resource Usage

sudo iotop              # Disk I/O monitoring
sudo nethogs            # Network usage per process
free -h                 # Memory usage
lsof -p 1234            # Open files for a process
lsof -i -P -n           # Network connections

Real-World Examples

Finding resource hogs: ps aux --sort=-%mem | head -5

Monitoring user activity: ps -u username -o pid,cmd,etime

Detecting suspicious processes: Unusual names, hidden from ps, running from /tmp, high network I/O may indicate malware.

Killing unresponsive scans: pkill -9 nmap

Common Mistakes

Using kill -9 as first resort — always try SIGTERM first. Ignoring zombie processes. Running GUI tools without backgrounding (wireshark &). Not using cgroups for resource limits in production.

Best Practices

Use top/htop for interactive monitoring. Always SIGTERM before SIGKILL. Use systemd for long-running processes. Monitor resources proactively. Use ulimit -n to check file descriptor limits.

Related Tools

htop — Enhanced process viewer. atop — Advanced monitor with logging. glances — Cross-platform monitoring. lsof — List open files. strace — Trace system calls. perf — Linux profiling.

Related Articles

  • linux-commands-explained
  • command-line-essentials
  • linux-terminal-guide
  • linux-file-permissions
  • kali-linux-beginner-guide
  • Summary

    Linux process management involves viewing (ps,top, htop), sending signals (kill, pkill), controlling priority (nice, renice), managing jobs (&, jobs, fg, bg), and administering systemd services (systemctl, journalctl).

    Knowledge Check

  • What are the main columns shown by ps aux?
  • What is the difference between SIGTERM and SIGKILL?
  • How do you run a command in the background?
  • What command checks systemd service status?
  • What does a zombie process indicate?
  • Frequently Asked Questions

    What is the difference between SIGTERM and SIGKILL?

    SIGTERM (kill -15) asks the process to shut down gracefully, allowing it to save data and release resources. SIGKILL (kill -9) forces immediate termination with no cleanup. Always try SIGTERM first — use SIGKILL only when a process ignores SIGTERM. See our Linux commands guide for more signals.

    How do I find which process is using a specific port?

    Use ss -tulpn | grep :80 or lsof -i :80 to find processes bound to a port. netstat -tulnp also works on older systems. For root processes, you may need sudo. This is essential for troubleshooting port conflicts and identifying unauthorized services.

    What does ps aux output mean?

    USER is the owner, PID is the process ID, %CPU and %MEM show resource usage, STAT indicates process state (R=running, S=sleeping, Z=zombie), and COMMAND shows the full command. Use ps aux --sort=-%mem | head to find memory hogs quickly.

    What is a zombie process and how do I fix it?

    A zombie process (Z state) has finished executing but its parent hasn't collected its exit status. Zombies consume no resources but indicate a parent process bug. Find them with ps aux | grep Z, identify the parent with ps -o ppid= -p PID, and fix or restart the parent process.

    How do I run a process in the background?

    Append & to any command: nmap -sV target &. Use Ctrl+Z to suspend a foreground process, then bg to send it to background. Use jobs to list background jobs and fg %1 to bring job 1 back to foreground. Use nohup to keep processes running after logout.

    What is systemctl and how do I use it?

    systemctl manages systemd services: systemctl status ssh checks status, sudo systemctl start/stop/restart ssh controls the service, and systemctl enable/disable ssh controls boot behavior. Use journalctl -u ssh -f to follow service logs in real time.

    What is the difference between nice and renice?

    nice sets priority when starting a process: nice -n 10 ./script.sh starts with lower priority (19 is lowest). renice changes priority of a running process: renice -n -5 -p 1234 requires root. Lower values mean higher priority — only root can use negative values.

    How do I monitor system resources in real time?

    Use htop for an interactive process viewer with sorting, filtering, and mouse support. Use iotop for disk I/O per process, nethogs for network usage per process, and free -h for memory overview. For persistent monitoring, install glances with sudo apt install glances.

    What are the different process states in Linux?

    R=Running or in run queue, S=Sleeping (interruptible), D=Uninterruptible sleep (I/O bound), T=Stopped by signal, Z=Zombie (terminated but not reaped). Use ps aux or top to see the STAT column. D-state processes are waiting for disk I/O and usually clear quickly.

    How do I kill all processes for a specific user?

    Use pkill -u username to terminate all processes owned by that user, or killall -u username for the same effect. For a specific process name, use pkill -9 firefox. Always verify with ps -u username before killing to avoid terminating critical processes.

    How do I check open files for a running process?

    Use lsof -p PID to list all files, network connections, and sockets for a specific process. lsof -i -P -n shows all network connections system-wide. For a specific file, lsof /var/log/syslog shows which processes have it open.

    What is the difference between nohup and disown?

    nohup makes a command immune to the HUP signal (sent when terminal closes) and redirects output to nohup.out. disown removes a job from the shell's job table so it won't receive HUP. Use nohup when starting new processes and disown for already-running background jobs.

    Continue Learning

    Linux · Beginner

    Bash Scripting Basics: Automate Tasks Like a Pro

    Learn Bash scripting from scratch covering variables, conditionals, loops, functions, error handling, and practical automation scripts for cybersecurity.

    Linux · Beginner

    Command Line Essentials: Mastering the Terminal for Security Work

    Essential command line skills for cybersecurity professionals including navigation, text processing, scripting, and automation.

    Linux · Beginner

    Linux Package Management: APT, DPKG, and Beyond

    Master Linux package management across Debian-based systems including APT, DPKG, repository configuration, dependency resolution, and troubleshooting.

    Linux · Beginner

    SSH Fundamentals: Secure Remote Access and Administration

    Learn SSH for secure remote access including key-based authentication, configuration, tunneling, port forwarding, and security hardening.

    Related Security Tools

    Web Application

    Commix

    Commix (Command Injection Exploiter) is an automated tool designed to test, detect, and exploit command injection vulnerabilities in web applications, facilitating automated OS shell access.

    Post Exploitation

    Evil-WinRM

    Learn how to use Evil-WinRM, a Ruby-based client for the Windows Remote Management (WinRM) protocol. This guide covers installation, your first connection, password, pass-the-hash and Kerberos authentication, file transfers and script execution, all for use in authorized lab environments.

    Exploitation

    MSFVenom

    MSFVenom is a standalone payload generator and encoder utility within the Metasploit Framework, first introduced in Metasploit 4.0 (2015) to replace the legacy msfpayload and msfencode tools with a single unified interface. It enables security professionals, penetration testers, and students to create, customize, and encode payloads for multiple platforms including Windows, Linux, macOS, Android, and PHP. MSFVenom is widely used in CTF competitions, security training labs, authorized penetration testing engagements, and red team operations to generate reverse shells, Meterpreter payloads, shellcode, and encoded executables. Understanding MSFVenom helps both offensive and defensive security professionals learn payload construction techniques, encoding methods, and detection strategies used in modern cybersecurity.

    Information Gathering

    SMBClient

    Learn how to use SMBClient on Kali Linux: install Samba's FTP-like SMB/CIFS client, list shares, connect as a guest or with credentials, browse folders, and upload or download files on Windows, Samba, or NAS devices. For authorized assessments, check ports 139/445 with Nmap before testing share permissions.

    Practice Linux Skills

    Command reference

    Linux Commands Reference

    Browse 163 practical Linux and Kali terminal commands.

    Interactive practice

    Terminal Sandbox

    Practice common Linux commands safely in your browser.

    Written by GO KALI FREE Team