Unix
February 19th, 2008 by admin
The basic signals on Unix -
Signals, to be short, are various notifications sent to a process in order to notify it of various “important” events. Each signal has an integer number that represents it (1, 2 and so on), as well as a symbolic name that is usually defined in the file /usr/include/signal.h. Each signal may have a signal handler, which is a function that gets called when the process receives that signal.
The function is called in “asynchronous mode”, meaning that nowhere in your program you have code that calls this function directly. Instead, when the signal is sent to the process, the operating system stops the execution of the process, and “forces” it to call the signal handler function. When that signal handler function returns, the process continues execution from wherever it happened to be before the signal was received, as if this interruption never occurred.
The difference between interrupts and signals is that while interrupts are sent to the operating system by the hardware, signals are sent to the process by the operating system, or by other processes.
Note that signals have nothing to do with software interrupts, which are still sent by the hardware (the CPU itself, in this case).
SIGINT: Linux sends a process this signal when the user tries to end it by pressing Ctrl+C
SIGSTP: Pressing this key causes the system to send a TSTP signal (SIGTSTP) to the running process. By default, this signal causes the process to suspend execution.
The abort function causes the process to receive this signal. By default, this signal causes the process to immediately terminate
SIGILL: A process gets this signal when it attempts to execute an illegal instruction. This could indicate that the program’s stack is corrupted.
SIGHUP: Linux sends a process this signal when it becomes disconnected from a terminal. Many Linux programs use SIGHUP for an unrelated purpose: to indicate to a running program that it should reread its configuration files.
SIGKILL: This signal ends a process immediately and cannot be handled.
SIGSEGV: The program attempted an invalid memory access. The access may be to an address that is invalid in the process’s virtual memory space, or the access may be forbidden by the target memory’s permissions. Dereferencing a “wild pointer” can cause a SIGSEGV
SIGBUS: Bus error — actually a misaligned address error
SIGALRM: The alarm system call schedules the delivery of this signal at a later time. See Section 8.13,: Setting Interval Timers,” in Chapter 8,“Linux System Calls,” for information about setitimer, a generalized version of
SIGPIPE : The program has attempted to access a broken data stream, such as a socket connection that has been closed by the other party.
SIGCHLD Linux sends a process this signal when a child process exits. See Section 3.4.4,“Cleaning Up Children Asynchronously,” in Chapter 3,“Processes.”
SIGKILL, SIGSTOP are the two signals that cannot be caught.
This entry was posted on Tuesday, February 19th, 2008 at 11:23 am and is filed under Technical. You can follow any responses to this entry through the RSS 2.0 feed. Responses are currently closed, but you can trackback from your own site.