Skip to main content
Hello — this lesson covers how to diagnose and manage processes on Linux systems. You’ll learn how processes are created, how to inspect running processes and the files they have open, and the common ways to terminate processes safely.

What is a process?

Whenever you run a program, the operating system creates a process for it. Processes fall into two broad categories:
  • Short-lived commands: utilities like ls, cp, or small scripts that run and exit quickly.
  • Long-lived services (daemons): system services like sshd that typically run continuously in the background.
Example: running ls spawns a short-lived process that lists directory contents and then exits:

Inspect running processes with ps

The primary tool for listing processes is ps. Important to note: ps supports two option styles that are not identical:
  • Unix/POSIX-style options use a leading dash (e.g., -A, -e).
  • BSD-style options do not use a leading dash (e.g., a, x, u).
Check the manual if behavior seems unexpected:
Running ps with no options shows processes associated with the current terminal/session:
A common, user-oriented way to view all processes is the BSD-style ps aux, which lists every process with human-friendly columns:
Key columns explained: Common ps option examples:

Inspect files a process has open with lsof

To see which files, sockets, or directories a process has open, use lsof (list open files). Use -p to specify a PID:
If the target process is owned by another user (for example, root), you will often need elevated privileges to get the full output. Prefix with sudo when necessary:
lsof may warn about incomplete output for certain filesystems (for example, FUSE filesystems used by virtual file systems). Example:

Terminate (kill) processes

When you need to stop a process, prefer graceful methods first, then escalate if necessary. Examples:
Best practices:
  • Try kill <PID> (SIGTERM) first so the process can clean up.
  • Use kill -9 <PID> (SIGKILL) only when the process is unresponsive.
  • Be careful when using pkill or killall on production systems — they can affect multiple processes.
Callout: ps option styles
Remember that ps accepts both BSD-style (no leading dash) and Unix/POSIX-style (leading dash) options. They are not interchangeable — check man ps if behavior seems unexpected.

Troubleshooting tips

  • If ps output is missing columns or looks different, you may be mixing BSD and Unix ps options. Consistently use ps aux or ps -ef depending on your needs.
  • When lsof reports permission errors or incomplete output, re-run with sudo to inspect system processes and protected files.
  • Use top or htop for real-time, interactive process monitoring and sorting by CPU or memory.

Summary

  • Processes are created when programs run; short-lived commands exit quickly while daemons run long-term.
  • ps is the standard tool to list processes. ps aux is a common BSD-style view; ps -ef is the Unix-style equivalent.
  • Use lsof -p \<PID>`to list files a process has open; run withsudo` to see processes owned by other users.
  • Terminate processes with kill for a graceful stop, and kill -9 only if necessary. Use pkill or killall when matching by name or pattern.

Watch Video