The Linux / Unix signals are used for transmitting a special condition to a process. In this article I will explain the basic things every Unix user should know about the signals.
The signals can be sent by both, the user and the kernel.
The signals that are usually transmitted by the kernel are:
- SIGSERV (signal segment violation) : sent when an invalid memory zone is accessed.
- SIGBUS : sent when an error occurs on the system’s bus.
- SIGFPE (signal floating point error) : sent when a floating error occurs
- SIGTERM (signal termination) : sent for quitting a process
- SIGKILL (signal kill) : sent for quitting a process forced.
The signals that are usually transmitted by the user are:
- SIGINT (signal interrupt) : intrerupts the current process
- SIGQUIT (signal quit) : signals the stopping of the current process
- SIGSTOP (signal stop) : suspends the current process
- SIGCONT (signal continue) : restarts the suspended process
The information about the signals sent by the kernel is for general knowledge only. In this article I will insint on the signals sent by the users.
There are more than 60 signals offered by the operating system. A complete list of signals can be displayed with the command: kill -l
$ kill -l
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 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
A signal has an identification number and a name, offering an ideea about its effect on the processes. I will pick only the most important signals, and give explenations, where necesarry:
- SIGHUP (1) (signal hang up) : this is used for restarting a process ; example: restart a daemon and ask him to reread the configuration file.
- SIGINT (2) (signal interrupt) : this is used for interrupting a proces ; usually, an interrupt process stops immediately.
- SIGQUIT (3) (signal quit) : this is used for stopping a process ; SIGQUIT can stop the processes that could not be killed with SIGINT.
- SIGILL (4) (signal illegal) : the process is executing an illegal instruction.
- SIGKILL (9) (signal kill) : this is the most powerfull signal ; it kills the process no matter what.
- SIGTERM (15) (signal termination) : this terminates a process ; the kernel sends SIGTERM to a process to ask him to cleanup because it will be stopped ith SIGKILL.
- SIGSTOP (19) (signal stop) : this suspends the current process.
- SIGCONT (18) (signal continue) : restart a suspended process.
How to send signals to processes:
The tools kill, killall and pkill are used for sending signals to processes. Read more about sending signals to processes here.
Signals can also be trasmitted to processes with combinations of keys:
- Ctrl – Z : this sends the SIGSTOP signal to the current process, suspending it. This is mostly used for sending a process in the run in the background.
- Ctrl – C : this sends the SIGINT signal to the current process, killing it. This is often used when a process freezes.
- Ctrl – \ : this sends the SIGQUIT signal to the current process. It forces the process to stop.