0
0
Linux CLIscripting~5 mins

kill and signal types in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes a program or process on your computer stops responding or needs to be stopped. The kill command lets you send signals to these processes to control or stop them safely or forcefully.
When a program freezes and you want to stop it without restarting your computer
When you want to politely ask a program to close and save its work
When a program ignores polite requests and you need to force it to stop immediately
When you want to send a custom signal to a process to trigger a specific action
When managing background tasks and you need to control their behavior
Commands
This command sends the SIGTERM signal to the process with ID 1234. SIGTERM politely asks the process to stop, allowing it to clean up before exiting.
Terminal
kill -SIGTERM 1234
Expected OutputExpected
No output (command runs silently)
-SIGTERM - Specifies the polite termination signal
This command sends the SIGKILL signal (signal number 9) to process 1234. It forcefully stops the process immediately without cleanup.
Terminal
kill -9 1234
Expected OutputExpected
No output (command runs silently)
-9 - Force kill signal that cannot be ignored
Lists all available signal names and their numbers so you can choose which signal to send.
Terminal
kill -l
Expected OutputExpected
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
Sends the SIGINT signal to process 1234, which usually interrupts the process as if you pressed Ctrl+C.
Terminal
kill -SIGINT 1234
Expected OutputExpected
No output (command runs silently)
-SIGINT - Interrupt signal to stop a process gracefully
Key Concept

If you remember nothing else from this pattern, remember: use SIGTERM to politely stop a process and SIGKILL to force it to stop immediately.

Common Mistakes
Using kill without specifying a signal and expecting it to force stop the process
By default, kill sends SIGTERM which the process can ignore or delay, so it may not stop immediately.
Use kill -9 to send SIGKILL if you need to force stop a process immediately.
Trying to kill a process with the wrong process ID
The kill command will fail silently or affect the wrong process if the ID is incorrect.
Verify the process ID using commands like ps or pidof before using kill.
Using kill -9 as the first option without trying polite signals
SIGKILL does not allow the process to clean up, which can cause data loss or corruption.
Try kill with SIGTERM first to allow graceful shutdown before using SIGKILL.
Summary
kill sends signals to processes to control or stop them.
SIGTERM (default) politely asks a process to stop, allowing cleanup.
SIGKILL (signal 9) forcefully stops a process immediately without cleanup.