Linux Processes Explained: ps, top, htop, kill, nice, and Process States

Linux & Administration

A Linux server is rarely doing just one thing. A web server may be accepting requests, a database may be writing data, scheduled jobs may be running, and your shell may be waiting for the next command. Linux represents each of these running activities as a process.

Understanding processes is one of the foundations of Linux administration. Once you can identify a process, read its state, inspect its resource use, and send it the correct signal, commands such as ps, top, htop, kill, and nice stop looking like unrelated tools. They become different ways of observing and controlling the same system.

⚡ Quick Answer

A process is a running instance of a program. Linux assigns it a process ID, or PID, tracks its state and resources, and schedules its execution on available CPUs.

Use ps for a snapshot, top or htop for live monitoring, kill to send signals, and nice/renice to influence CPU scheduling priority.

🎯 What You’ll Learn
  • What a Linux process is and how PID and PPID relationships work.
  • How to read common Linux process states such as R, S, D, T, and Z.
  • When to use ps, top, and htop.
  • What kill actually does and why SIGTERM should normally come before SIGKILL.
  • How nice values influence normal CPU scheduling.
  • How to inspect processes safely on a real Linux machine.

🐧 What Is a Linux Process?

A program stored on disk is passive. It is a file containing executable instructions. When Linux loads that program and begins executing it, the running instance becomes a process.

For example, /usr/bin/bash is an executable file. Start Bash, and Linux creates a process for it. Run another Bash shell and you now have another process, even though both were created from the same executable.

Executable
on disk
Program is
started
Linux creates
a process
Scheduler gives
it CPU time

A process has much more than executable code. Linux also tracks information such as its process ID, owner, memory mappings, open files, environment, scheduling information, parent relationship, and current state.

🔢

PID

A numeric identifier assigned to a process. Administrators use PIDs to inspect or target specific processes.

🌳

PPID

The PID of the process’s parent, helping show how processes were created and how they relate to each other.

🔄

State

A compact description of what the process is currently doing, such as running, sleeping, stopped, or waiting.

🌳 Processes Form a Hierarchy

Linux processes do not normally appear from nowhere. A running process creates another process, making the new process its child. This produces a process hierarchy.

Suppose you open a shell and run a command:

sleep 300

Your shell is the parent process. The new sleep process is its child. The child therefore has its own PID and records the shell’s PID as its PPID.

You can make this relationship visible with:

ps -o pid,ppid,user,stat,comm

The exact processes shown depend on the current terminal and environment, but the important columns are straightforward:

Column Meaning Why It Matters
PID Process ID Identifies one process.
PPID Parent process ID Shows which process created or parents it.
USER Process owner Helps explain permissions and ownership.
STAT Process state and additional flags Helps diagnose what the process is doing.
COMMAND / COMM Command or executable name Helps identify the workload.
💡 Academy Insight

A PID tells you which process you are looking at. A PPID helps tell you where that process came from. When troubleshooting, both are often useful.

🔍 Using ps: A Snapshot of Processes

ps reports process information at the moment the command runs. Think of it as taking a photograph of the process table.

Running ps without options usually shows only a limited set of processes associated with your current terminal and user context:

ps

A commonly used broader view on Linux systems with procps-ng is:

ps aux

This gives you information about many processes on the machine, typically including process ownership, PID, CPU and memory-related columns, start information, and the command.

For administrative work, custom output is often easier to understand than memorizing every column of a large default display:

ps -eo pid,ppid,user,stat,%cpu,%mem,comm

You can also inspect one known PID:

ps -p 1234 -o pid,ppid,user,stat,etime,comm

Replace 1234 with an actual PID from your system.

🔄 Understanding Linux Process States

A process can exist without actively executing instructions on a CPU at that instant. Most processes spend large amounts of time waiting for something.

Linux exposes process-state information through the /proc interface, and utilities such as ps translate that information into compact state codes.

State Meaning Practical Interpretation
R Running or runnable The task is executing or ready to receive CPU time.
S Interruptible sleep The process is waiting for an event and can be awakened. This is normal and very common.
D Uninterruptible sleep The task is waiting in an uninterruptible state, commonly while the kernel waits for certain I/O-related work.
T Stopped Execution has been stopped, for example by a signal.
Z Zombie The process has exited, but its parent has not yet collected its termination status.

Beginners often assume that a process marked S is broken because it is “sleeping.” Usually the opposite is true. A server process that is waiting for the next connection or event should not burn CPU continuously. Sleeping efficiently is part of normal operation.

What is a zombie process?

A zombie is not a process that is still doing work. It has already terminated. A small amount of process-table information remains so that its parent can retrieve the child’s termination status.

That distinction matters because sending another termination signal to the zombie itself does not solve the underlying parent/child bookkeeping problem. Persistent or accumulating zombies point you toward the parent process and its handling of terminated children.

⚠️ Common Mistake

Do not interpret every unusual process state as a reason to kill the process. State is diagnostic information. First identify the process, its role, its parent, and what it is waiting for.

📊 top: Watching Processes Live

ps answers “what existed when I checked?” top answers a different question: “what is happening over time?”

top

top continuously refreshes system and process information. Depending on configuration and implementation, the display includes system load information, task counts, CPU activity, memory information, and a changing list of processes.

Typical process columns include:

  • PID — process ID.
  • USER — process owner.
  • PR — scheduling priority representation.
  • NI — nice value.
  • %CPU — CPU usage reported by the tool.
  • %MEM — process memory percentage.
  • COMMAND — task or command name.

Because the screen refreshes, top is useful when a performance problem is intermittent or when you want to see whether one process repeatedly rises to the top of the CPU list.

Press q to quit.

💡 Academy Insight

A process appearing near the top of top is not automatically a problem. Resource usage has to be interpreted in context. A process doing useful CPU-intensive work may legitimately consume significant CPU time.

🖥️ htop: A More Interactive Process Viewer

htop serves a similar monitoring purpose but provides a more interactive terminal interface. It commonly offers easier scrolling, process selection, tree-style views, sorting, and interactive process actions.

htop

Unlike ps and commonly available procps tools, htop may not already be installed on a particular Linux system. Package availability and installation commands depend on the distribution.

Tool View Best Use
ps One-time snapshot Scripts, precise queries, inspection, filtering, and reproducible command output.
top Live terminal view Watching CPU activity and process behavior change over time.
htop Interactive live view Exploration when a friendlier interactive interface is useful and htop is installed.

Learning ps and top is still valuable even if you prefer htop. On an unfamiliar or minimal server, you should not assume every optional utility is installed.

📨 What kill Actually Does

The name kill is slightly misleading. The command’s fundamental job is to send a signal to a process. A signal is an asynchronous notification delivered to a process by the operating system.

For example:

kill 1234

With the usual kill interface, omitting an explicit signal requests SIGTERM. SIGTERM asks the target process to terminate.

You can state the signal explicitly:

kill -TERM 1234

That is fundamentally different from:

kill -KILL 1234

SIGKILL cannot be caught, blocked, or ignored by the target process. The kernel terminates the process rather than allowing the process to handle that signal itself.

SIGTERM vs. SIGKILL

Signal Purpose Process Can Handle It? Typical Administrative Approach
SIGTERM Request termination Yes Usually try this first so software has the opportunity to shut down cleanly.
SIGKILL Force termination No Reserve for cases where forced termination is actually necessary.
⚠️ Before Sending Signals

Verify the PID and understand what the target process does. Terminating the wrong process can interrupt services, sessions, writes, or application work. Prefer a service’s normal management mechanism when you are intentionally managing a system service.

⚙️ nice: Influencing CPU Scheduling

When several runnable tasks compete for CPU time, the Linux scheduler has to decide how that CPU time is distributed. For normal time-sharing scheduling, a process’s nice value is one input that can influence its scheduling weight.

On Linux, nice values conventionally range from -20 to 19. The direction often surprises beginners:

  • A higher nice value means the process is being “nicer” to competing tasks and receives less favorable scheduling treatment.
  • A lower nice value means more favorable scheduling treatment.
  • A nice value of 0 is the conventional baseline.

To start a new command with an adjusted niceness:

nice -n 10 command

For a harmless example:

nice -n 10 sleep 300

To change the nice value of an already running process, Linux systems commonly provide renice:

renice 10 -p 1234

Replace 1234 with the target PID.

Permissions matter. An ordinary user can generally make owned processes less favored by increasing the nice value, while making a task more favored by decreasing its nice value may require additional privilege or an appropriate resource limit.

💡 Academy Insight

Niceness is not a CPU speed setting. Changing it does not guarantee that a process will use a particular percentage of a CPU. It influences scheduler preference under relevant scheduling conditions, especially when runnable tasks compete for CPU time.

🧠 A Practical Troubleshooting Model

When someone says “the server is slow,” immediately killing the busiest-looking process is poor process management. A better workflow moves from identification to interpretation and only then to action.

1

Identify the process

Use ps, top, or htop to determine which processes are relevant.

2

Understand its identity

Check the PID, owner, parent process, command, and role. A process name alone may not provide enough context.

3

Inspect its state and resources

Determine whether it is actively running, sleeping, blocked, stopped, or already terminated as a zombie. Observe CPU and memory information rather than guessing.

4

Decide whether action is necessary

High activity may be expected. A sleeping process may be perfectly healthy. Intervention should follow diagnosis rather than replace it.

5

Use the least disruptive action

If intervention is required, use the mechanism appropriate to the workload. For termination, a graceful request such as SIGTERM is normally preferable to immediately forcing SIGKILL.

🧪 Mini Lab: Observe a Process From Start to Finish

🧪 Mini Lab

Goal: create a harmless process, find its PID, inspect its state and parent, then terminate it gracefully.

Step 1 — Start a safe background process.

sleep 300 &

Your shell should report a job number and normally the PID of the new process.

Step 2 — Find the process.

ps -o pid,ppid,user,stat,ni,comm -C sleep

What to observe: find the sleep process you just created. Note its PID, PPID, state, and nice value. On a typical system, a process whose purpose is to wait will spend its time sleeping rather than continuously running on a CPU.

Step 3 — Inspect that specific PID.

ps -p PID -o pid,ppid,user,stat,ni,etime,comm

Replace PID with the actual numeric PID.

Step 4 — Ask it to terminate.

kill -TERM PID

Step 5 — Check again.

ps -p PID

If the process has terminated and been reaped normally, it will no longer appear under that PID.

⚠️ Common Process Management Mistakes

❌ Mistake: Assuming sleeping means unhealthy

Processes frequently sleep while waiting for input, timers, connections, or other events. Efficient waiting is normal behavior.

❌ Mistake: Using SIGKILL as the first response

SIGKILL prevents the target from handling the termination signal. When appropriate, a graceful termination request gives software an opportunity to perform its normal shutdown logic.

❌ Mistake: Treating high CPU usage as proof of failure

A process performing legitimate computational work may use substantial CPU. Resource consumption is evidence to investigate, not a diagnosis by itself.

❌ Mistake: Confusing a program with a process

An executable is stored code. A process is a running instance. Multiple processes can execute the same program at the same time and still have different PIDs and runtime state.

❌ Mistake: Thinking nice sets a fixed CPU percentage

Niceness influences scheduling preference. It does not directly reserve or cap a specific percentage of CPU time.

✅ Knowledge Check

✅ Knowledge Check
  1. What is the fundamental difference between an executable program and a process?
  2. Why can a healthy server contain many processes in the S state?
  3. When would top be more useful than a single ps command?
  4. What does the kill command actually do?
  5. Why is SIGTERM generally preferable to immediately sending SIGKILL?
  6. If you increase a normal process’s nice value from 0 to 10, what scheduling effect are you requesting?
🎓 Check Your Answers
  1. An executable program is stored code, while a process is a running instance of that program with its own runtime identity and resources, including a PID and process state.
  2. The S state represents interruptible sleep. Many processes correctly spend most of their time waiting for events instead of consuming CPU continuously, so sleeping is often evidence of normal behavior rather than failure.
  3. top is more useful when you need to watch process and resource activity change over time. ps normally gives you a snapshot from the moment the command runs.
  4. kill sends a signal to a process. Termination is a common use, but the command itself is fundamentally a signal-delivery interface rather than simply a “force stop” command.
  5. SIGTERM gives a process the opportunity to handle a termination request and perform its normal shutdown behavior. SIGKILL cannot be caught, blocked, or ignored, so the target process cannot handle it before the kernel terminates it.
  6. You are requesting less favorable scheduling treatment relative to competing tasks. A larger nice value means the process is being “nicer” to other runnable workloads; it does not specify a fixed CPU percentage.
🎓 Servers Academy — Key Takeaway

Linux process management is not mainly about killing processes. It is about observing running work, understanding its state, and choosing the correct level of intervention.

Remember the tool roles: ps gives you a snapshot, top/htop help you watch activity, signals communicate with processes, and nice values influence scheduling preference. Diagnose first; control second.

Rate article
Add a comment