Linux Signals
Linux Signals
Linux Signals
1. What is a signal a. A signal is a very short message that may be sent to a process or group of processes 2. What is purpose of signal? a. Signal has two purposes. i. To make a process aware that a specific event has occurred ii. To cause a process to execute a signal handler function in its code 3. What is a signal handler? a. 4. What are real-time signals? a. Real time signals are those capable of queued so that multiple signals sent will be received. 5. What is the real time signal range? a. Signal numbers range from 32-64. 6. What is the difference between regular signal and real time signal? a. Regular signals cannot be queued while real time signal can be queued. 7. What are phases of signal? a. Phases of signal are signal generation and signal delivery 8. What are pending signals? a. Signals that have been generated but not yet delivered are called pending signals. 9. Signal behavior? a. Signals are usually delivered only to the currently running process. b. Signals of a given type may be selectively blocked by a process i. In this case the process does not receive signal until it removes block c. When a process executes signal a signal handler function, it usually masks the corresponding signal. i. Therefore, a signal handler cannot be interrupted by another occurrence of the same signal and the function doesnt need to be reentrant. 10. What are actions performed upon delivering a signal? a. There are 3 ways in which a process can respond to a signal i. Explicitly ignore the signal ii. Execute the default action associated with signal. This action is predefined by kernel and depends on signal type. It may be any of the following Terminate The process is terminated (Killed) Dump The process is terminated and a core file containing its execution context is created. It is called core dump. This file may be used for debug purposes. Ignore Signal is ignored Stop Process is stopped that is put the task in TASK_STOPPED Continue If the process was stopped, it is put into TASK_RUNNING iii. Catch the signal by invoking a corresponding signal handler function 11. What are pending signal queues?
15.
a. There are 2 pending signal queues i. shared pending signal queue ii. private pending signal queue What is a shared pending signal queue? a. Stores the pending signal of the whole thread group What is a private pending signal queue? a. Stores the pending signal of the specific light weight process How to catch signal? a. A non blocked signal is sent to a process. i. When interrupt or exception occurs process switched from user mode to kernel mode. ii. Kernel executes do_signal() function which in turn handles the signal by invoking handle_signal() and sets user mode stack by invoking setup_frame() or setup_rt_frame() iii. Back in user mode process starts executing the signal handler, because the handlers starting address was forced into the program counter. Whe that function terminates, the return code placed on the user mode stack by the setup_frame() or setup_rt_frame() is executed. This code invokes sigreturn() or the rt_sigreturn() iv. The corresponding service routines copy the hardware context to the normal program to the kernel mode stack and restore the user mode stack back to its original state by invoking restore_signcontext() Signals and their description # 1 2 3 4 5 6 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Signal Name SIGHUP SIGINT SIGQUIT SIGILL SIGTRAP SIGABRT SIGIOT SIGBUS SIGFPE SIGKILL SIGUSR1 SIGSEGV SIGUSR2 SIGPIPE SIGALRM SIGTERM SIGSTKFLT SIGCHLD SIGCONT SIGSTOP Default Action Terminate Terminate Dump Dump Dump Dump Dump Dump Dump Terminate Terminate Dump Terminate Terminate Terminate Terminate Terminate Ignore Continue Stop Comment Hang up controlling terminal or process Interrupt from key board Quit from key board Illegal instruction Brakpoint for debugging Abnormal termination Equivalent to SIGABRT Bus error Floating-Point exception Forced-Process termination Available to processes Invalid memory reference Available to processes Write to pipe with no readers Real-Time Clock Process termination Coprocessor stack error Child process stopped or terminated, or got signal if traced Resume action, if stopped Stop process execution POSIX Yes Yes Yes Yes No Yes No No Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes
20 21 22 23 24 25 26 27 28 29 29 30 31 32
SIGTSTP SIGTTIN SIGTTOU SIGURG SIGCPU SIGXFSZ SIGVTALRM SIGPROF SIGWINCH SIGIO SIGPOLL SIGPWR SIGSYS SIGUNUSED
Stop Stop Stop Ignore Dump Dump Terminate Terminate Ignore Terminate Terminate Terminate Dump Dump
Stop process issued from tty Background process requires input Background process requires output Urgent condition on socket CPU time limit exceeded File size limit exceeded Virtual timer clock Profile timer clock Window resizing I/O now possible Equivalent to SIGIO Power supply failure Bad System call Equivalent to SIGSYS
16. Most significant system calls and description System call kill() tkill() tgkill() sigaction() signal() sigpending() sigprocmask() sigsuspend() rt_sigaction() rt_sigpending() rt_sigprocmask() rt_sigqueueinfo() rt_sigsuspend() rt_sigtimedwait Description Send a signal to the thread group Send a signal to process Send a signal to process in a specific thread group Change the action associated with signal Similar to sigaction() Check whether there are pending signals Modify the set of blocked signals Wait for a signal Change the action associated with a real-time signal Check whether there are pending real-time signals Modify the set of blocked real-time signals Send a real-time signal to a thread group Wait for a signal Similar to rt_sigsuspend()