Full Byte Developer.

Ctrl+C is SIGINT

The terminal sends SIGINT on Ctrl+C; default handling terminates the process unless you catch the signal.

Published here , updated · 5 sources

Ctrl+C is not magic: the terminal delivers SIGINT, which is the interrupt-from-keyboard signal named in Linux signal(7) [1]. The default disposition is to terminate the running foreground process [1]. Related reads: what happens when you press Enter and threads vs processes.

Quick start (under a minute)

List signal names on Linux:

bash
kill -l | grep SIGINT

You should see SIGINT beside number 2. That number is what Python and C headers use when they say signal.SIGINT or SIGINT.

Read the signal table row from the man page

Linux signal(7) [1]:

SignalMeaningDefault
SIGINTInterrupt from keyboardTerm
SIGTERMTermination signalTerm
SIGKILLKill (cannot be caught)Term

Other signals cover stop, continue, faults, and alarms. This page stays on the interactive interrupt path [1].

Catch SIGINT in Python on this host

Python's signal module installs handlers for asynchronous events such as signals [2]. Minimal pattern:

python
import signal
import sys
import time

def on_sigint(signum, frame):
    print("got SIGINT signum=%d" % signum, file=sys.stderr)
    sys.exit(130)

signal.signal(signal.SIGINT, on_sigint)
print("running; sending SIGINT next", flush=True)
while True:
    time.sleep(0.2)

Send SIGINT with kill -INT <pid> (same signal as Ctrl+C in a tty) [1].

Observed on this draft host (Python 3.12.3, Linux, 2026-12-03):

text
running; sending SIGINT next
got SIGINT signum=2

Shell reported exit status 130 after that run, matching the 128+2 convention many shells use for signal deaths [3]. Without a handler, the default terminate path ends the process without your cleanup [1].

Exit code 130 is a teaching convention, not a POSIX law. Bash documents exit statuses for pipelines and signals separately; script authors should test on their target shell [3].

Place Ctrl+C in the terminal pipeline

Pressing Enter submits a line to the shell, which may exec a child (what happens when you press Enter). While that child is in the foreground process group, Ctrl+C goes to the child as SIGINT, not to the shell's prompt loop [1].

Multi-threaded programs still receive signals at the process level. Which thread runs the handler is platform and runtime specific. Read threads vs processes before claiming each thread gets its own Ctrl+C.

The shell survives because it is not the foreground job unless you interrupted an empty line at prompt (behavior can vary slightly by shell settings).

Do not confuse SIGINT with kill -9

kill -15 or kill <pid> sends SIGTERM, a polite shutdown request many daemons catch to flush logs [1]. kill -9 sends SIGKILL, which cannot be caught or ignored [1]. Operators call that a hard kill.

Ctrl+C is SIGINT, softer than SIGKILL, sharper than ignoring the program. Teach teammates to prefer handlers that flush work then exit, instead of spreading the myth that Ctrl+C "force quits the terminal."

Job control and who is in the foreground

Bash job control tracks foreground and background process groups [3]. When you run ./long_task, that child is foreground until it exits. Ctrl+C delivers SIGINT to that group. When you background a job with & or bg, it is no longer foreground; Ctrl+C at the prompt may generate a new line instead of interrupting the background job. Use fg to bring it forward if you need to interrupt it interactively.

stty settings can remap keys, but the default on Linux ttys maps interrupt to Ctrl+C. GUI terminals emulate the same behavior by sending the interrupt character to the pty master.

What happens if you catch SIGINT but never exit

A handler that only prints a message and returns leaves the process running [2]. That surprises users who expect Ctrl+C to stop a runaway loop. Document "press Ctrl+C twice" only if you implement it deliberately. Long-running data tools often catch once for graceful shutdown, then reset to default on a second interrupt.

SIGKILL remains the backstop when a process ignores SIGINT and SIGTERM [1]. Orchestrators use staged signals: TERM first, KILL after a timeout. Ctrl+C is not in that path unless a human is at the keyboard.

Interrupt during blocking system calls

If your process is blocked in certain syscalls (read, write, connect), Linux may restart the syscall after a handled SIGINT or return EINTR depending on flags [1]. Python's signal docs note that not all C extension modules restart cleanly [2]. That is why some CLIs set a flag in the handler and check it after I/O returns instead of calling sys.exit inside the handler itself.

Ctrl+C in pipelines

In a shell pipeline cmd1 | cmd2, signal delivery follows shell rules: Ctrl+C may terminate the whole pipeline or only the foreground stage depending on shell options (set -m, bash set -o pipefail, etc.) [3]. If cmd1 buffers and cmd2 is slow, interrupting may leave a zombie stage. For teaching, run the simple single-process demo above before debugging pipelines.

Pty versus raw SSH without tty

ssh host command without a pseudo-terminal may not map your local Ctrl+C to the remote process the way an interactive session does. ssh -t allocates a tty when you need interrupt semantics. Containers started without -it behave similarly: signals reach PID 1 rulesets, not always your app.

Signal masks in worker threads

POSIX threads can block signals with pthread_sigmask while the main thread handles them [1]. Python documents that signal handlers should be registered on the main thread [2]. Worker pools that swallow interrupts can leave the parent process running after Ctrl+C appears to do nothing. When that happens, check which thread owns the handler before blaming the terminal.

Common mistakes and misconceptions

Thinking Ctrl+C kills the terminal app. It signals the foreground process. Your shell session stays open.

Expecting SIGINT during docker run attach or ssh remote sessions exactly like local tty. PTY forwarding and job control change who is foreground. When in doubt, use kill -INT <pid> on the known child.

Every language exposes the same handler rules. Python documents main-thread handler registration limits [2]. JVM and Go have their own notes. Read the platform page before shipping a CLI.

Using Ctrl+C during git rebase or editors without reading the key binding. Some tools map Ctrl+C to cancel input, not POSIX SIGINT to child. Context matters.

Exit code 130 always means SIGINT. Scripts can exit 130 manually, as the demo does with sys.exit(130) [2]. Combine exit codes with logs, not superstition.

Try the handler sketch on a throwaway script, then run a long job and note whether exit code 130 shows up in your shell. When a pipeline misbehaves, compare foreground groups with the Enter and exec story in what happens when you press Enter. For threaded tools where only one thread may register handlers, pair this page with threads vs processes before you blame the keyboard.

Send this to the friend who mashes Ctrl+C and thinks the shell itself died.

Teal and orange arrows from stacked slabs through a glowing concentric-ring sphere into transparent cubes with tiny linked nodes beside a teal-outlined black cube, no people.
Ctrl+C maps to SIGINT for the foreground job, not the whole terminal session.

Keep this guide

By Full Byte Developer

Filed under Dev explainers, Dev tools

Questions about this guide

What signal is Ctrl+C?

On Linux, signal 2 is SIGINT: interrupt from keyboard, default action terminate the process. The terminal driver turns the Ctrl+C keystroke into SIGINT for the foreground process group, not for the shell session as a whole.

Is SIGINT the same as SIGTERM?

No. SIGTERM (15) is the generic termination request many init systems and orchestrators send first. SIGINT is the keyboard interrupt path. Both default to terminate, but they arrive through different mechanisms and tools document different cleanup expectations.

Can a program ignore Ctrl+C?

A program can install a handler or set SIG_IGN for SIGINT, within platform rules. Python documents handler limits (main thread, certain system calls). Ignoring interrupts without an exit plan strands operators; document behavior in long-running CLIs.

Why do I sometimes see exit code 130?

Shells often report 128 plus signal number for deaths by signal. SIGINT is 2, so 130 is a common convention when a process dies on Ctrl+C. Verify on your shell if scripts branch on exit codes.

Sources

Next in this stack