Bash Index : K - The 'K' Bash commands : description, flags and examples

kill / killall

Usage :

from the softest to the toughest kill :
  1. kill -1
  2. kill -15
  3. kill -9
The CTRL'ed keys and the shell (Source 1, 2) :

When a CTRL-... key sequence is pressed in a terminal, the terminal sends a corresponding signal to the shell, which forwards it to the stdin of the currently running program.
Mapping of key sequences / signals : stty -a
Bash shortcut keys

Flags :

Flag Usage
-l list available signals
-signalName
-s signalName
send the signal signalName :
kill -s stop 12345
kill -s STOP 12345
kill -s sigstop 12345
kill -s SIGSTOP 12345

sleep 10 & kill -1 $!
sleep 10 & kill -hup $!
sleep 10 & kill -sighup $!
sleep 10 & kill -s hup $!
sleep 10 & kill -s sighup $!
Signal Description # Usage
SIGHUP Hangup 1 This argument makes kill send the Hang Up signal to processes. This probably originates from the modem/dial-in era. Processes have to be programmed to actually listen to this signal and do something with it. Most daemons are programmed to re-read their configuration when they receive such a signal. Anyway, this is very likely the safest kill signal there is, it should not obstruct anything.
SIGINT Interrupt 2 This signal is sent to the program being executed when CTRL-c is pressed in a terminal. Most programs will stop, you may lose data.
SIGQUIT Quit and dump core 3
SIGILL Illegal instruction 4
SIGTRAP Trace/breakpoint trap 5
SIGABRT Process aborted 6
SIGBUS Bus error: "access to undefined portion of memory object" 7
SIGFPE Floating point exception: "erroneous arithmetic operation" 8
SIGKILL Kill (terminate immediately) 9 The kernel will let go of the process without informing the process of it :
  1. the process will vanish immediately, without completing its current task
  2. the process won't have the opportunity to free its resources (RAM, files, sockets, ...)
  3. children processes won't be notified of their father dying. As orphans, they'll be adopted by init

kill -9 could result in data loss. This is the "hardest", "roughest" and most unsafe kill signal available, and should only be used to stop something that seems unstoppable.

This signal is NOT catchable.
SIGUSR1 User-defined 1 10
SIGSEGV Segmentation violation 11
SIGUSR2 User-defined 2 12
SIGPIPE Write to pipe with no one reading 13
SIGALRM Signal raised by alarm 14
SIGTERM Termination (request to terminate)
This is the default signal.
15 Tell the process to :
  1. stop whatever it's doing
  2. inform its children processes that it's being stopped
  3. wait for children processes to stop
  4. free resources
  5. end itself
This is a normal process shutdown, which is safe to perform. Not a bad idea anyway trying to send a -1 / -HUP signal 1st.
There _may_ be situations where the process is on an uninterruptible task and ignores this signal.
SIGCHLD Child process terminated, stopped (or continued*) 17
SIGCONT Continue if stopped 18
SIGSTOP Stop executing temporarily 19 This signal is NOT catchable.
SIGTSTP Terminal stop signal 20 This signal is sent after a CTRL-z in a terminal.
SIGTTIN Background process attempting to read from tty ("in") 21
SIGTTOU Background process attempting to write to tty ("out") 22
SIGURG Urgent data available on socket 23
SIGXCPU CPU time limit exceeded 24
SIGXFSZ File size limit exceeded 25
SIGVTALRM Signal raised by timer counting virtual time: "virtual timer expired" 26
SIGPROF Profiling timer expired 27
SIGPOLL Pollable event 29
SIGSYS Bad syscall 31

More about signals :

  • for details : man 7 signal
  • catchable signals : when such a signal is sent to a process, it is able to catch it with trap (or ignore it) and perform various "shutdown" operations it needs to do. Non-catchable signals affect the process immediately.