Loading...

Lab 16: Process Management and Job Control

Identify resource-hungry processes, validate what is actually running, and take controlled action to stabilize the system. Use standard tools to inspect, terminate, and reprioritize workloads, and manage background jobs safely.

core troubleshooting services

Scenario

A Linux host is running slowly and user sessions feel laggy. You need to identify a process that is consuming excessive CPU, confirm system state using both snapshot and live views, terminate the runaway workload safely, and ensure you can manage shell jobs and scheduling priority without making the system worse.

Operator context

This is the workflow you use before escalating to “the server is slow” tickets or guessing. You validate what is running, prove which process is responsible, and take the smallest safe corrective action.

Objective

  • Capture a quick process snapshot with CPU and memory visibility.
  • Inspect live process behavior to confirm the top offender.
  • Terminate a runaway process using a controlled signal.
  • List, foreground, and manage shell jobs safely.
  • Start a workload at a lower scheduling priority using nice.

What You’ll Practice

  • Fast process inspection using ps aux and targeted output filtering with head.
  • Live process monitoring using top to confirm CPU-heavy workloads in real time.
  • Process termination basics using kill (SIGTERM) for controlled shutdown.
  • Shell job control using jobs and fg.
  • Scheduling priority adjustment using nice to reduce impact on system responsiveness.

Walkthrough

Step 1 : Take a quick snapshot of processes with CPU and memory columns.
Command
ps aux | head -n 5

ps aux provides a wide process listing including %CPU and %MEM. Piping into head gives you a quick baseline view without flooding the terminal. This is useful for confirming the machine is not “empty” and spotting obvious outliers.

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1 167936  1104 ?        Ss   Jul18   0:02 /sbin/init
root       402  0.1  0.3  98720  3128 ?        Ss   08:01   0:00 /lib/systemd/systemd-journald
root       711  0.0  0.2  72960  2140 ?        Ss   08:01   0:00 /usr/sbin/cron -f
lab       1357 25.3  4.1 248112 42280 ?        Rl   12:45   1:37 /usr/bin/python3 script.py
Step 2 : Confirm the top offender using a live process view.
Command
top

top gives a real-time view of CPU, memory, and per-process usage. Use this to confirm that the same PID is consistently consuming CPU, not just spiking briefly. This reduces the chance you terminate the wrong process.

top - 12:48:33 up  2:47,  1 user,  load average: 2.23, 2.10, 1.76
Tasks: 188 total,   2 running, 186 sleeping,   0 stopped,   0 zombie
%Cpu(s): 38.6 us,  3.1 sy,  0.0 ni, 57.9 id,  0.1 wa,  0.0 hi,  0.3 si,  0.0 st
MiB Mem :   7860.0 total,   1180.5 free,   2387.2 used,   4292.3 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   4970.1 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 1357 lab       20   0  248.1m  41.3m   5.1m R  98.3  0.5   1:39.21 python3
 (Press 'q' to quit top)
Step 3 : Terminate the runaway process using a controlled signal.
Command
kill 1357

kill without a signal defaults to SIGTERM, which requests a graceful shutdown. This is a safe first move because it allows the process to exit cleanly. If a process ignores SIGTERM, you can escalate, but start here.

bash: sent SIGTERM to PID 1357
Step 4 : List background jobs in the current shell.
Command
jobs

Job control is shell-scoped. jobs shows what you have running in the background in your current session. This matters when you need to recover control of a long-running script, pause work, or bring a task back into focus.

[1]-  Running                 ./bigjob.sh &
Step 5 : Bring a background job back into the foreground.
Command
fg %1

fg resumes a background job in the foreground so you can interact with it directly. If there are multiple jobs, targeting by job spec (like %1) prevents you from foregrounding the wrong task.

./bigjob.sh
(running in foreground; press Ctrl+Z to background)
Step 6 : Start a workload with a lower scheduling priority.
Command
nice -n 10 ./backup.sh

nice runs a command with an adjusted niceness value. Higher niceness generally means lower CPU scheduling priority, which helps keep the system responsive while background work runs. This is a common operator move when you need work to complete without impacting interactive users.

started './backup.sh' with nice value +10 (lower priority)

Reference

  • ps aux : Snapshot of all processes with user, CPU, memory, and full command details.
  • head -n <N> : Prints only the first N lines of output to keep listings readable.
  • top : Interactive, live view of system load and per-process CPU/memory usage.
  • kill <PID> : Sends a signal to a process (defaults to SIGTERM) for controlled termination.
  • jobs : Lists jobs started from the current shell session.
  • fg : Brings a background job to the foreground (use fg %<job> to target).
  • nice -n <value> <command> : Starts a command with an adjusted niceness (higher value usually means lower priority).