linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Processes & resources/signals

kb/processes ── Processes & resources ── beginner

Signals (SIGTERM, SIGKILL, SIGHUP)

A signal is an asynchronous notification to a process from the kernel or another process. TERM asks it to quit, KILL kills it now, HUP reloads config.

view as markdownaka: signal, sigterm, sigkill, sighup, sigint

What a signal is

A signal is a tiny integer notification that the kernel delivers to a process. The process can handle the signal (install a handler), ignore it, or do nothing. In that last case the default action runs, and the default is usually "terminate".

The most important signals

signal#default actionwhen it is sent
SIGHUP1terminateTTY closed; for services, "reload config"
SIGINT2terminateCtrl+C in a terminal
SIGQUIT3core dumpCtrl+\
SIGKILL9terminatedirect kill, cannot be handled or ignored
SIGTERM15terminatethe standard "please shut down"
SIGSTOP19stoppause the process, cannot be handled
SIGCONT18continueresume a stopped process
SIGUSR1/210/12terminatefor the application; often used to give a command without a restart
SIGPIPE13terminateyou write to a pipe whose reader has closed
SIGCHLD17ignorea child process exited, so you need wait()
SIGSEGV11core dumpaccess to invalid memory

The correct shutdown pattern

Send TERM first, give it a few seconds for a graceful exit, then KILL:

bash
kill <pid>            # send TERM
sleep 5
kill -KILL <pid>      # if still alive, finish it off

A well-behaved service handles TERM by closing its listening sockets, finishing the current requests, flushing buffers, and saving state. A plain kill -9 tears all of that apart: lost transactions, corrupted files, stuck DB locks.

Which signal to use when

  • TERM is the ordinary "stop", your default
  • KILL only when TERM did not work
  • HUP for daemons means "reload config" (nginx, syslog)
  • USR1/2 can mean anything the application defines: for example, nginx USR1 is log rotation
  • STOP/CONT pause and resume a process, useful for long-running batch jobs

Where all this is configured

In bash, signals are overridden through trap:

bash
trap 'echo got SIGINT; exit 1' INT
trap 'cleanup; exit' EXIT

§ команды

bash
kill -l

List all signals with their numbers

bash
kill -TERM 1234

Send SIGTERM to a specific PID

bash
pkill -HUP nginx

Send SIGHUP to every process by name (nginx reloads its config)

bash
killall -9 chrome

By name, to every process, forced SIGKILL as a last resort

bash
trap 'echo bye' EXIT

In bash, install a handler for the EXIT signal that runs when the shell exits

§ см. также

  • process-and-pidProcess and PIDA process is a running program with its own PID, memory, open descriptors, and UID. Every process forms a tree rooted at init (PID 1).
  • oom-killerOOM killerOOM killer is the kernel mechanism that picks and terminates a process when the system hits its memory limit. In containers it works per-cgroup.
  • cmd-psps: process snapshotps prints a snapshot of processes at the moment it runs. Two dialects: BSD (`aux`, no dash) and UNIX (`-ef`, with dash). `-o` specifies columns. For continuous monitoring, use [[cmd-htop|htop]].
  • cmd-htophtop: interactive process monitorhtop is an interactive TUI process monitor. F-keys: F3 search, F4 filter, F5 tree, F6 sort, F9 kill. Color meters at the top, process list below. It replaces top wherever it is available.

§ упоминается в уроках

  • ›advanced-06-ebpf-trace
  • ›beginner-05-permissions
  • ›beginner-07-processes-and-signals
  • ›beginner-09-environment-and-shell
  • ›intermediate-07-debugging-with-proc
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies