Leaving presentation mode.

Monitor and Manage Linux Processes

Dennis Kibbe

Mesa Community College

Keyboard Shortcuts

This slide presentation was created by B6Plus. The audio accompanying this presentation is AI-generated.

Module Outline

Learning Objectives

After completing the work in this module you will be able to:

Process States and Lifecycle

Determine status, resource use, and ownership of running programs on a system, to control them.

Definition of a Process

A process is a running instance of a program and consists of memory, scheduling for time on the CPU, and other system resources.

The Process Environment

Describe Process States

Each CPU core can run a single process at a time. The illusion of multitasking is maintained by quickly switching among processes.

Zombie processes should not be confused with orphan processes, a process that is still executing, but whose parent has died. When the parent dies, the orphaned child process is adopted by init. - Wikipedia.

Importance of Process States

Understanding process states can help in troubleshooting a system that is not performing as expected.

Listing Processes


[student@workstation ~]$ ps
PID       TTY     TIME        CMD
10430     pts/1   00:00:00    bash
10458     pts/1   00:00:00    ps
      

The ps command without options displays a static list of processes in the current shell only. With its many options the listing can be customized to include system processes, processes run by a particular user, and much more.

Graded Quiz

Process States and Lifecycle

Complete this graded quiz in Canvas.

Control Jobs

Use Bash job control to manage multiple processes that were started from the same terminal session.

Describe Jobs and Sessions

[student@workstation ~]$ ps
PID       TTY     TIME        CMD
2640     pts/1   00:00:00    bash
2672     pts/1   00:00:00    ps
      

Only a single job at a time can accept user input. A shell can run additional jobs in the background. The ps command lists the jobs in the current shell.

Run Jobs in the Background

[student@workstation ~]$ sleep 30 &
[1] 2677
[student@workstation ~]$ jobs
[1]+  Running   sleep 30 &
      

Adding an ampersand (&) after a command starts it in the background. The jobs command shows jobs running in the background.

Guided Exercise

Control Jobs

In this Guided Exercise you practice using job control to start, suspend, and move multiple processes to the background and foreground.

Kill Processes

Use commands to kill and communicate with processes, define the characteristics of a daemon process, and stop user sessions and processes.

🛠 Process Control with Signals

[student@workstation ~$] kill -l
1) SIGHUP	  2) SIGINT	 3) SIGQUIT	 4) SIGILL	 5) SIGTRAP
6) SIGABRT  7) SIGBUS	 8) SIGFPE	 9) SIGKILL	10) SIGUSR1
11) SIGSEGV	12) SIGUSR2	13) SIGPIPE	14) SIGALRM	15) SIGTERM
16) SIGSTKFLT	17) SIGCHLD	18) SIGCONT	19) SIGSTOP	20) SIGTSTP      
      

A signal is a software interrupt that is delivered to a process. The kill command with the l option lists the signals available.

Send Signals by Explicit Request (SIGTERM)

The kill command without an option sends the default SIGTERM (15) signal. This instructs the process to clean up temporary files and stop.

Send Signals by Explicit Request (SIGKILL)

If the process doesn't respond to the SIGTERM (15) signal. The SIGKILL (9) signal will kill the process. It's the bullet through the head. It will be messy with temporary files and allocated memory left behind.

Signal Multiple Processes

[user@host ~]$ killall firefox
Terminated /usr/lib/firefox/firefox-bin
Terminated /usr/lib/firefox/plugin-container
      

Some processes may have multiple threads such as Firefox. The killall command can terminate all threads with a single command.

Terminate Background Jobs

[student@workstation ~]$ jobs
[1]-  Running   sleep 30 &
[2]+  Running   sleep 60 &
    
[student@workstation ~]$ kill -SIGTERM %1
[1]-  Terminated  sleep 30
    

Here two instances of the sleep command are running in the background. The kill command is used with the job number (%1) to terminate the desired job.

Guided Exercise

Kill Processes

In this guided exercise you use signals to manage and stop processes.

Monitor Process Activity

The top command displays resource-intensive processes and load average in real time. The display is refreshed every 3 seconds.

Describe Load Average

Load Average is a measure of how busy the CPU is.

Load Average Calculation

[user@host ~]$ uptime
 15:29:03 up 14 min,  2 users,  load average: 2.92, 4.48, 5.20
      

The average load or load average on a system is calculated using the number of cores a CPU has. When the load average is higher than the number of CPU cores some processes must wait to run on the CPU and the system will feel sluggish. Load average is measured one minute, five minutes, and 15 minutes ago.

Interpret Load Average Values

[user@host ~]$ lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              4      
      
[user@host ~]$ uptime
 15:29:03 up 14 min,  2 users,  load average: 2.92, 4.48, 5.20
      

To make sense of a system's load average you can use the lscpu command to find the number of CPU cores.

Real-time Process Monitoring

The top command updates every three seconds and shows much useful information about a system. In addition top can terminate a run away process.

Guided Exercise

Monitor Process Activity

Use the top command to examine running processes and control them dynamically.

Summary

  1. A process is a running instance of a program.
  2. Each process is in a state (running, sleeping, stopped, or zombie).
  3. Each terminal has its own session with foreground and background processes.
  4. The kill, pkill, and killall commands send signals to control a process.
  5. Load Average is a measure of how busy the system is and is displayed with the top, uptime, or w commands.

Resources

Graded Lab

Monitor and Manage Linux Processes

Locate and manage processes that use the most resources on a system.

Thanks for Watching

Thanks for watching. This is the end of the presentation.

Created on 17 February 2025 by Dennis Kibbe. Last modified on 9 June 2025 09:21:00 by DNK.