> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Managing Processes and Jobs

> Guide to managing UNIX processes and shell jobs, using signals, job control (fg/bg/jobs), kill and killall, and interactive tools like top

Let's start controlling processes. This guide shows how to stop, resume, and terminate processes by sending signals, and how to manage foreground and background jobs using the shell and interactive tools.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/9E2T0ocsNwD7Od8i/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Process-Management-Tuning/Demo-Managing-Processes-and-Jobs/demo-managing-processes-jobs-gear-database.jpg?fit=max&auto=format&n=9E2T0ocsNwD7Od8i&q=85&s=0e043b9171bee0997cd028ff8f8f965b" alt="A dark presentation slide titled &#x22;Demo: Managing Processes and Jobs.&#x22; On the right is a blue line-art icon of a gear rising from waves with an upward arrow pointing to a stacked database cylinder." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/Process-Management-Tuning/Demo-Managing-Processes-and-Jobs/demo-managing-processes-jobs-gear-database.jpg" />
</Frame>

The goal is to become comfortable running and managing tasks so you can control long-running commands, recover a suspended job, or terminate misbehaving processes.

## Starting and controlling jobs

A shell job can run in the foreground or background. Foreground jobs attach to the terminal and block it, while background jobs run asynchronously.

Common job-control actions:

| Action | Command / Keystroke | Notes |
| - | - | - |
| Start a foreground job | `sleep 100` | Runs attached to terminal |
| Suspend (stop) foreground job | `Ctrl+Z` | Sends SIGTSTP to the process |
| List shell jobs | `jobs` | Shows job IDs and states |
| Resume stopped job in background | `bg %<job>` (e.g., `bg %1`) | `%<job>` is the job ID shown by `jobs` |
| Bring job to foreground | `fg %<job>` (e.g., `fg %1`) | Restores terminal control to the job |
| Start a job directly in background | `sleep 200 &` | `&` forks the job into background |
| Show job IDs with PIDs | `jobs -l` | Displays underlying process IDs (PIDs) |

Tip: Use job IDs (`%1`, `%2`, ...) when using `fg`/`bg`. Use `jobs -l` to map job IDs to PIDs.

<Callout icon="lightbulb" color="#1CB2FE">
  Use `jobs -l` when you need the PID to send signals (for example with `kill`). Job IDs (like `%1`) are shell-local; PIDs are system-wide.
</Callout>

Example interactive session demonstrating these actions:

```bash theme={null}
root@control:~# sleep 100
^Z
[1]+  Stopped                 sleep 100
root@control:~# jobs
[1]+  Stopped                 sleep 100
root@control:~# bg %1
[1]+ sleep 100 &
root@control:~# jobs
[1]+  Running                 sleep 100 &
root@control:~# fg %1
sleep 100
^Z
[1]+  Stopped                 sleep 100
root@control:~# sleep 200 &
[2] 6120
root@control:~# jobs
[1]+  Stopped                 sleep 100
[2]-  Running                 sleep 200 &
root@control:~# jobs -l
[1]+  6112 Stopped                 sleep 100
[2]-  6120 Running                 sleep 200 &
root@control:~#
```

## Sending signals with kill

Processes respond to signals (e.g., to stop, continue, or terminate). Use `kill` to send a signal to a PID.

* `kill <pid>` sends SIGTERM (15) by default — a polite request to terminate.
* `kill -9 <pid>` sends SIGKILL (9) — forces immediate termination; cannot be caught or ignored.
* `kill -l` lists signal names/numbers available on the system.

Common signals:

| Signal | Number | Typical use |
| - | -: | - |
| `SIGTERM` | `15` | Graceful termination; allows cleanup |
| `SIGKILL` | `9` | Immediate kill; no cleanup possible |
| `SIGSTOP` | — | Stop (suspend) a process; cannot be caught |
| `SIGCONT` | — | Continue a stopped process |
| `SIGINT` | `2` | Interrupt (same as Ctrl+C) |

Example: listing signals and using `kill`:

```bash theme={null}
root@control:~# 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
21) SIGTTIN         22) SIGTTOU         23) SIGURG          24) SIGXCPU         25) SIGXFSZ
26) SIGVTALRM       27) SIGPROF         28) SIGWINCH        29) SIGIO           30) SIGPWR
31) SIGSYS          34) SIGRTMIN        35) SIGRTMIN+1      36) SIGRTMIN+2      37) SIGRTMIN+3
38) SIGRTMIN+4      39) SIGRTMIN+5      40) SIGRTMIN+6      41) SIGRTMIN+7      42) SIGRTMIN+8
43) SIGRTMIN+9      44) SIGRTMIN+10     45) SIGRTMIN+11     46) SIGRTMIN+12     47) SIGRTMIN+13
48) SIGRTMIN+14     49) SIGRTMIN+15     50) SIGRTMAX-14     51) SIGRTMAX-13     52) SIGRTMAX-12
53) SIGRTMAX-11     54) SIGRTMAX-10     55) SIGRTMAX-9      56) SIGRTMAX-8      57) SIGRTMAX-7
58) SIGRTMAX-6      59) SIGRTMAX-5      60) SIGRTMAX-4      61) SIGRTMAX-3      62) SIGRTMAX-2
63) SIGRTMAX-1      64) SIGRTMAX
root@control:~# jobs -l
[1]+  6112 Stopped                 sleep 100
[2]-  6120 Running                 sleep 200 &
root@control:~# kill -9 6112
[1]+  Killed                  sleep 100
root@control:~# kill 6120
[2]+  Terminated              sleep 200
root@control:~#
```

<Callout icon="warning" color="#FF6B6B">
  Use `kill -9` (SIGKILL) only when necessary — it prevents the process from cleaning up temporary files or gracefully closing resources. Try `kill` (SIGTERM) first.
</Callout>

For more detail, see the kill manual: [man 1 kill](https://man7.org/linux/man-pages/man1/kill.1.html).

## Killing multiple processes by name

To send a signal to all processes that match a command name, use `killall <name>`. This sends the default signal (SIGTERM) to every matching process name.

Example:

```bash theme={null}
root@control:~# sleep 200 &
[1] 6159
root@control:~# sleep 200 &
[2] 6161
root@control:~# sleep 200 &
[3] 6165
root@control:~# sleep 200 &
[4] 6167
root@control:~# killall sleep
```

After `killall sleep`, all running `sleep` processes are terminated.

## Using top to send signals interactively

Interactive process viewers like `top` let you send signals without leaving the tool.

* While `top` is running, press `k` to prompt for a PID and a signal number or name.
* Enter the PID, then the signal (e.g., `9` or `SIGKILL`) to send it.

Example `top` snapshot (when `k` is used you are prompted for a PID and a signal):

```bash theme={null}
top - 15:00:46 up 47 min,  4 users,  load average: 0.00, 0.03, 0.00
Tasks: 288 total,   1 running, 286 sleeping,   1 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.1 sy,  0.0 ni, 99.5 id,  0.0 wa,  0.2 hi,  0.1 si,  0.0 st
MiB Mem :   3652.4 total,   1744.1 free,   1445.3 used,    694.4 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   2207.1 avail Mem
PID to signal/kill [default pid = 2577]
UID     PID COMMAND                      PPID TTY      USER     RUSER     TIME+   %CPU %MEM S
1000    2577 gnome-shell                  2438 ?        student  student  0:35.45  0.5 11.6 S
1000    3465 ptyxis                       2438 ?        student  student  0:30.07  2.0  9.7 S
1000    2678 ibus-daemon                  2438 ?        student  student  0:04.64  0.0  0.3 S
0       1    systemd                      0    ?        root     root     0:02.50  0.0  1.1 S
1000    3059 ibus-engine-sim              2678 ?        student  student  0:01.91  0.0  0.2 S
1000    2784 ibus-extension-              2678 ?        student  student  0:01.78  0.0  0.8 S
1000    3067 pipewire                     2438 ?        student  student  0:01.30  0.0  0.3 S
1000    3472 ptyxis-agent                 3465 ?        student  student  0:00.96  0.0  0.2 S
1000    2758 gnome-software               2550 ?        student  student  0:00.94  0.0  2.8 S
0       73   khugepaged                   2    ?        root     root     0:00.78  0.0  0.0 S
0       3116 rhsm-service                  1    ?        root     root     0:00.77  0.0  1.7 S
0       588  kworker/u29:1-events_unbound  2    ?        root     root     0:00.67  0.0  0.0 I
114     1149 polkitd                       1    ?        polkitd  polkitd  0:00.65  0.0  0.3 S
0       161  kworker/u28:2-events_unbound  2    ?        root     root     0:00.61  0.0  0.0 I
0       1280 tuned                         1    ?        root     root     0:00.60  0:00  0.8 S
0       168  kworker/u25:3-events_unbound  2    ?        root     root     0:00.58  0.0  0.0 I
0       4297 kworker/u28:3-events_unbound  2    ?        root     root     0:00.53  0.0  0.0 I
1000    3070 wireplumber                  2438 ?        student  student  0:00.51  0.0  0.6 S
0       4567 kworker/u27:3-events_unbound  2    ?        root     root     0:00.51  0.0  0.0 I
0       835  xfsaild/dm-0                  2    ?        root     root     0:00.50  0.0  0.0 S
81      1142 dbus-broker                   1120 ?       dbus     dbus     0:00.45  0.0  0.2 S
```

Enter the PID to signal and the signal number/name when prompted.

## Quick reference

| Task | Command |
| - | - |
| Suspend current foreground job | `Ctrl+Z` |
| List jobs | `jobs` |
| Background a job | `bg %<job>` |
| Foreground a job | `fg %<job>` |
| Start background job | `command &` |
| Show jobs with PIDs | `jobs -l` |
| Send signal to PID | `kill <pid>` or `kill -SIGNAL <pid>` |
| Kill processes by name | `killall <name>` |
| Send signals from top | Run `top`, press `k` |

## Summary

* Use shell job control (Ctrl+Z, `fg`, `bg`, `jobs`) to pause and resume tasks without killing them.
* Prefer `kill <pid>` (SIGTERM) so processes can terminate gracefully; use `kill -9` (SIGKILL) as a last resort.
* Use `killall` to target processes by name when appropriate.
* Interactive tools like `top` provide convenient ways to inspect processes and send signals.
* For more details, see the bash job control documentation and the `kill` and `top` man pages:
  * [Bash job control](https://www.gnu.org/software/bash/manual/html_node/Job-Control-Basics.html)
  * [man 1 kill](https://man7.org/linux/man-pages/man1/kill.1.html)
  * [man 1 top](https://man7.org/linux/man-pages/man1/top.1.html)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/7b99b8b8-7c3c-4787-940b-bbf5e334aaa6/lesson/7bd5aac1-357d-4005-8570-332fe01f374c" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.