Friday, October 10, 2014

Unix Prog: Signal List

1. Signal Introduction
Signals provide a way of handling asynchronous events: a user at a terminal typing the interrupt key to stop a program or the next program in a pipeline terminating prematurely.

2. Conditions generating signals
1) When user press certain terminal keys. For example, DELETE Key or Ctrl C normally causes signal SIGINT to be generated
2) Hardware exceptions generate signals, divide by 0, invalid memory reference, etc.
3) kill system call allows the user to send a signal to a process. And the user need to be the owner of the process or super user
4) kill command in shell is similar from kill system call.
5) Software conditions can generate signals, for example, SIGALRM signal, generated when an alarm clock set by the process expires.

3. Disposition of the signal
1) Ignore the signal. SIGKILL and SIGSTOP signals can never be ignored. Also, for hardware exception signal, ignoring it may cause program have undefined behavior
2) Catch the signal. We tell the kernel to call a function of ours whenever the signal occurs
3) Apply the default action. For most signals, default action is to terminate the process.

4. The core file
When the process is terminated, sometimes, kernel will generate the core file , which is the memory image of the process when it is terminated. It can be put into most debuggers to examine the state of the process when it is terminated.

The core file will not be generated if:
1) The process's effective user id is set by the set-user-id bit of the program, and current real user is not the owner of the program file
2) The process's effective group id is set by the set-group-id bit of the program, and current real group id is not the group owner of the program file.
3) The user doesn't have permission to write in the current directory.
4) The file already exists, and user doesn't have permission to write to it.
5) The file is too big.

5. Signal List:
 ubuntu@ip-172-31-23-227:~$ less /usr/include/asm-generic/signal.h  
 #define SIGHUP      1  
 #define SIGINT      2  
 #define SIGQUIT     3  
 #define SIGILL      4  
 #define SIGTRAP     5  
 #define SIGABRT     6  
 #define SIGIOT      6  
 #define SIGBUS      7  
 #define SIGFPE      8  
 #define SIGKILL     9  
 #define SIGUSR1     10  
 #define SIGSEGV     11  
 #define SIGUSR2     12  
 #define SIGPIPE     13  
 #define SIGALRM     14  
 #define SIGTERM     15  
 #define SIGSTKFLT    16  
 #define SIGCHLD     17  
 #define SIGCONT     18  
 #define SIGSTOP     19  
 #define SIGTSTP     20  
 #define SIGTTIN     21  
 #define SIGTTOU     22  
 #define SIGURG     23  
 #define SIGXCPU     24  
 #define SIGXFSZ     25  
 #define SIGVTALRM    26  
 #define SIGPROF     27  
 #define SIGWINCH    28  
 #define SIGIO      29  
 #define SIGPOLL     SIGIO  
 /*  
 #define SIGLOST     29  
 */  
 #define SIGPWR     30  
 #define SIGSYS     31  
 #define SIGUNUSED    31  
   
 /* These should not be considered constants from userland. */  
 #define SIGRTMIN    32  
 #ifndef SIGRTMAX  
 #define SIGRTMAX    _NSIG  
 #endif  

SIGABRT: generated by calling the abort function
SIGALRM: generated when a timer set with the alarm function expires
SIGBUS: implementation-defined hardware fault
SIGCHLD: Whenever a process terminates or stops, the SIGCHLD signal is sent to the parent
SIGCONT: the job-control signal is sent to a stopped process when it is continued, default action is to continue the stopped process, but it is ignored if the process is not stopped.
SIGFPE: arithmetic exception, such as divide by 0, float-point overflow
SIGHUP: the signal is sent to the controlling process(session leader) associated with a controlling terminal if a disconnect is detected by the terminal interface. The signal is also sent to the each process of the foreground process group if the session leader is terminated.
SIGILL: sent when the process executed the illegal hardware instruction.
SIGINT: generated by the terminal driver when we type the interrupt key(often DELETE or Ctrl - C). This signal is sent to all processes in the foreground process group.
SIGIO: the signal indicates an asynchronous I/O event.
SIGIOT: the signal indicates the implementation-defined hardward fault.
SIGKILL: the signal can't be caught or ignored. It provides a sure way to kill the process.
SIGPIPE: if we write to a pipeline but the reader has terminated, SIGPIPE is generated.
SIGPOLL: the signal can be generated when a specific event occurs on a pollable device.
SIGPROF: generated when a profiling interval timer set by the setitimer(2) function expires.
SIGPWR: if power fails, UPS takes over and the software can usually be notified. If the battery gets low, it behooves the system to shut everything down within about 15-30 seconds. This is when SIGPWR should be sent.
SIGQUIT: generated by the terminal driver when we type the terminal quit key(often Ctrl-backslash). The signal is sent to all processes in the foreground process group.
SIGSEGV: indicates that the process has made an invalid memory reference.
SIGSTOP: the job-control signal that stops a process. and it can not be caught or ignored.
SIGSYS: indicates an invalid system call.
SIGTERM: termination signal sent by the kill command by default
SIGTRAP: indicates an implementation-defined hardware fault
SIGTSTP: interactive signal generated by the terminal driver when we type the terminal suspended key(often ctrl-z). the signal is sent to all processes in the foreground processes.
SIGTTIN: generated by the terminal driver when a process in a background process group tries to read from its controlling terminal. If: 1) the process is ignoring or blocking the signal  2) the reading process is orphaned, then signal is not generated and read operations returns an error with errno set to EIO.
SIGTTOU: generated by the terminal driver when a process in a background process group tries write to its controlling terminal. If: 1) the process is ignoring or blocking the signal 2) the writing process is orphaned, then signal is not generated and write operations returns an error with errno set to EIO.
SIGURG: notify the process that an urgent condition has occurred.
SIGUSR1, SIGUSR2: user-defined signal, for use in the application programs.
SIGVTALRM: generated when a virtual interval timer set by the setitimer function expires.
SIGWINCH: a process can get and set the window size with the ioctl function. once that happens, the kernel will generate the SIGWINCH signal for the foreground process group.
SIGXCPU: if the process exceeds its soft CPU time limit, the SIGXCPU signal is generated.
SIGXFSZ: generated if the process exceeds its soft file size limit.
SIGXRES: generated if the process exceeds a preconfigured resource value.

No comments:

Post a Comment