Linux · Systems fluency

How do you inspect processes with ps and top?

MediumpstopmonitoringUpdated Oct 2026
Quiz this track

Short answer

ps gives a point-in-time snapshot of process state, while top refreshes continuously and shows CPU and memory consumption. Use ps for precise filtering and top for live sorting and trends.

ps reads process data from /proc and prints the selected fields. The options differ between BSD and System V styles, so choose one style consistently. top samples the system repeatedly and sorts by CPU by default.

sh
ps aux --sort=-%cpu | head
ps -eo pid,ppid,stat,pcpu,pmem,cmd --sort=-pmem | head
top -b -n 1 | head -n 15

Columns that matter

  • PID and PPID identify the process and its parent
  • STAT shows state plus modifiers such as nice, session leader, or multithreaded
  • %CPU is a sampling estimate, not an exact CPU-time measurement
  • RSS is resident memory; VSZ includes virtual mappings that may never be resident
  • NI is the nice value that influences scheduler priority

In top, press M to sort by memory, P by CPU, and 1 to see per-core utilization. Inside containers, tools may show host-level data unless the container has its own PID namespace and cgroup-aware tooling.

Short-lived processes can disappear between snapshots. For repeated sampling use pidstat, or enable process accounting if you need historical attribution.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What is the difference between RSS and VSZ?
  2. 2Why can top show a process using more than 100 percent CPU?
  3. 3How do you find the process listening on a specific port?
  4. 4Why might top inside a container show host processes?

Say it in the interview

ps is a snapshot and top is a live sampling view. I use ps when I need exact field selection or filtering, and top when I need to watch CPU and memory change. The key columns are PID, parent, state, CPU, and resident memory. I remember that CPU percentages are samples and that container views can be misleading.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Linux mock interview and get scored feedback on depth, clarity and confidence.