Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Linux Process Commands: ps, top, pstree, nice, renice

Lesson 15 of 31 in the free Operating System & Linux Programming notes on Siksha Sarovar, written by Rohit Jangra.

Observing Processes

Linux exposes processes through the /proc filesystem. The user-space tools below read /proc.

ps — Process Snapshot

ps prints a one-time list of processes. Common forms:

  • ps — only your terminal's processes.
  • ps -e or ps -A — every process.
  • ps -ef — full format.
  • ps aux — BSD form, with %CPU and %MEM.
  • ps -o pid,ppid,user,stat,cmd — custom columns.

The STAT column codes: R running, S sleeping, D uninterruptible, Z zombie, T stopped.

top and htop — Live Monitor

top refreshes every few seconds. Inside, press P to sort by CPU, M by memory, k to kill, r to renice, q to quit.

htop is a friendlier alternative with colour bars and tree view (F5).

pstree — Process Hierarchy

pstree shows the parent-child tree, useful to understand which shell launched what.

Process Priorities

Linux schedules with two related concepts:

  • Nice value — user-tunable, range -20 (highest priority) to +19 (lowest). Default 0.
  • Priority — actual scheduling priority computed by the kernel.

nice — Launch with Reduced Priority

nice -n 10 ./long_job.sh starts the script with niceness 10 — friendlier to other processes. Only the superuser can request a negative niceness.

renice — Change a Running Process's Priority

renice +5 -p 1234 raises the niceness of PID 1234 by 5 (lower priority). Use -u user to renice all processes of a user.

Sending Signals

kill PID sends SIGTERM. kill -9 PID sends SIGKILL (cannot be caught). pkill name matches by name. killall name kills all matching.

Worked Example

Find the heaviest CPU consumer and lower its priority:

  1. ps -eo pid,pcpu,cmd --sort=-pcpu | head
  2. Note the PID, say 5678.
  3. renice +10 -p 5678 — gentler scheduling.
  4. top -p 5678 — confirm the change.

Summary

  • ps snapshot, top/htop live, pstree hierarchy.
  • nice/renice tune scheduling priority via the niceness knob.
  • kill sends signals; -9 is the unstoppable SIGKILL.