> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Use SIGINT and Other Termination Signals in Linux
- URL: https://linuxhandbook.com/termination-signals/
- Published: 2022-10-15T09:55:57.000Z
- Updated: 2023-06-01T14:50:46.000Z
- Description: Terminating executing process is more than just kill -9. Here are some of the prominent termination signals and their usage.
- Author: Sagar Sharma
- Tags: Quick Tip

You must be used to use Ctrl + C for terminating any process, but do you know it sends the `SIGINT` signal? 

But there are more types of terminating signals than just using `SIGINT` (cough Ctrl + c cough). So let's dive deep into the ocean of terminating signals!!

## Use Termination Signals in Linux

[The kill command is what users generally use for termination](https://linuxhandbook.com/kill-process/) but do you know that 50+ signals kill command avails you? 

![signals that can be paired with kill command](https://linuxhandbook.com/content/images/2022/10/kill--l.png)

This means you can use those numbers instead of writing the signal name. 

For example, if you want to stop execution ([suspending a running process](https://linuxhandbook.com/suspend-resume-process/)), you're most likely to use `SIGTSTP` like this:

```
kill -SIGTSTP %jobID
```

![how to use kill command with signals](https://linuxhandbook.com/content/images/2022/10/examp1.png)

Similarly, you can use `20` as it is associated with `SIGTSTP` to have the same effect: 

```
kill -20 %jobID
```

![use associated numbers with signals to kill process](https://linuxhandbook.com/content/images/2022/10/examp2.png)

But there are too many options so I'm going to cover widely used ones. 

So let's start with the `SIGSTP`. 

### Terminate processes using SIGTSTP

First, let me start with the [killing foreground process](https://linuxhandbook.com/kill-process/). 

It is quite simple compared to killing background processes, as you just have to use keybindings accordingly. 

The keybinding of executing `SIGTSTP` is `ctrl + z`. For example, I'll be [using the sleep command](https://linuxhandbook.com/bash-sleep/): 

```
sleep 15000
```

![use SIGTSTP with a kill to terminate foreground processes](https://linuxhandbook.com/content/images/2022/10/sleep-15000.png)

Here you can see I've used [the jobs command](https://linuxhandbook.com/jobs-command/), a helpful utility that shows running and recently terminated processes. 

But what about [background processes](https://linuxhandbook.com/run-process-background/)? Well, there, you'd need to use the kill command specifying PID or JOB ID with `-SIGTSTP`. 

```
kill -SIGSTP %jobID
```

![use SIGTSTP with a kill to terminate background processes](https://linuxhandbook.com/content/images/2022/10/kill-background-process.png)

### Use SIGCONT to resume command execution

There are times when you want to resume the command execution that you terminated recently and in those cases, `-SIGCONT` will help you. 

For this example, I'll be using the previously terminated process and then use the given command to resume its execution:

```
kill -SIGCONT %jobID
```

![resume terminated process using SIGCONT](https://linuxhandbook.com/content/images/2022/10/cont-jobs.png)

### Terminate execution using SIGINT

This is my all-time favorite command, as whenever I find myself stuck somewhere, `ctrl + c` makes wonders for me. 

And if you're not aware of this, let me show you how it can terminate command executions with ease:

![use SIGINT with a kill to terminate foreground processes](https://linuxhandbook.com/content/images/2022/10/Screenshot-from-2022-10-11-14-34-47.png)

But the problem with `SIGINT` is it may not work in some places such as bash interpreters. 

For example, here's a bash script that takes input from the user:

```
#!/bin/bash

trap date SIGINT

read input
echo User input: $input
echo Exiting now
```

![bash script showing SIGINT might not work for certain cases](https://linuxhandbook.com/content/images/2022/10/bash.png)

As you can see, it gave me the current date and time when I pressed `ctrl + c` and only stopped when it got input from my side.

I know this script was created in that way but you got my point right. You can not rely on `SIGINT` always.

### Use SIGQUIT for termination

The SIGQUIT is similar to SIGINT but it also generates a core dump before execution. 

In simple words, the core dump is a file that is generated automatically before the system crashes or the process is terminated. 

Also, It can be provoked by using `ctrl + \`. So you can use it for terminating foreground and background processes.

So let me show you how it behaves when you only try `ctrl + \` :

![use SIGQUIT with to terminate foreground processes](https://linuxhandbook.com/content/images/2022/10/core-dump.png)

But how to use it for terminating background processes? Let me bring light to the syntax part to make it easier:

```
kill -SIGQUIT %jobID
```

![use SIGQUIT with to terminate background processes](https://linuxhandbook.com/content/images/2022/10/using-for-backgripound.png)

### Terminate executions using SIGTERM

As its name suggests, this is a termination signal that terminates the program but unlike SIGKILL (that kills the program no matter what), this is a polite way of asking the program to be terminated.

If you want to learn more about [SIGTERM vs SIGKILL](https://linuxhandbook.com/sigterm-vs-sigkill/), I'd recommend the other guide that touches on the core fundamentals:

[What is SIGTERM? What’s the difference between SIGKILL & SIGTERM?Both SIGTERM and SIGKILL are used for killing a process in Linux. But you should prefer using SIGTERM. Here’s why!![](https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png)Linux HandbookAbhishek Prakash![](https://linuxhandbook.com/content/images/2020/06/dont_sigkill_use_sigterm.jpg)](https://linuxhandbook.com/sigterm-vs-sigkill/)

One thing to remember is that sometimes it performs cleanups before proceeding with termination. 

So the syntax of `SIGTERM` is quite simple:

```
kill -SIGTERM %jobID
```

![use SIGTERM to terminate background processes](https://linuxhandbook.com/content/images/2022/10/termination.png)

### Use SIGKILL (the last resort)

⚠️

It is always advised to use SIGKILL as a last resort because it will kill any child process immediately making it the most brutal way of killing processes!

Once in a while, I found myself in a situation where some programs won't work at all and they can't be terminated at all!

So in those cases, I use `SIGKILL` to give that process the most unpleasant death. 

Now, let's have a look at the generic syntax of SIGKILL:

```
kill -SIGKILL %jobID
```

![use SIGKILL to terminate background processes](https://linuxhandbook.com/content/images/2022/10/job-killed.png)

## Wrapping Up

This guide was a basic explanation of how you can use varieties of signal options to terminate executions. And if you still have any doubts, let me know in the comments.