110 likes | 245 Views
UNIX System Programming. Signals: Wrap-up. Summary. See section 7.4 of Hoover text signal() kill() Lots of “tricky stuff” that you can read about at in the prior signals-UNIX notes or online. continued. Signals. A “low-bandwidth” form of communication between processes:
E N D
UNIX System Programming Signals: Wrap-up
Summary • See section 7.4 of Hoover text • signal() • kill() • Lots of “tricky stuff” that you can read about at in the prior signals-UNIX notes or online. continued
Signals A “low-bandwidth” form of communication between processes: • typically 30-40 signal types • Receiving process may handle or ignore • “signal handler” is a function that executes when a signal is received • Current process is interrupted • Signal is handled • Current process resumes
Signal handlers • Each process has a default signal handler for each signal • default typically terminates the process • signal() – installs a signal handler, or tells process to ignore the signal • signal(SIGFPE, some-function); where • void some-function(int) • signal(SIGINT, SIG_IGN); UNIX System Programming: Signals Maria Hybinette
Common Signals UNIX System Programming: Signals Maria Hybinette
Common Signals, continued UNIX System Programming: Signals Maria Hybinette
Generating signals • By users, OS, or other processes • User at the keyboard: • Ctrl-C Pressing this key causes the system to send an INT signal (SIGINT) to the running process. By default, this signal causes the process to immediately terminate. • Ctrl-Z 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. • Ctrl-\ Pressing this key causes the system to send a ABRT signal (SIGABRT) to the running process. By default, this signal causes the process to immediately terminate. UNIX System Programming: Signals Maria Hybinette
Generating signals • User from the command line: • kill -INT 5342 • Kill –USR1 20166 • From a process: • kill(pid, SIGSTOP) UNIX System Programming: Signals Maria Hybinette
The “Reset” Problem • The Traditional System-V Signal Environment • inherited its signal-handling environment from V7 research UNIX. • has three major limitations: • Recursive signal handling is always allowed. • Signal handlers are reset to SIG_DFL prior to being called. • System calls interrupt when a signal is delivered. • These limitations cause "unreliable" signal behavior: Since signals can be delivered recursively and the signal handler must manually reset the signal handler from SIG_DFL, there is a window during which the default signal handler can be called if another signal of the same type arrives. In many cases the default action is to ignore the signal, causing the signal to be lost. In the worst case the default action is to terminate the process. UNIX System Programming: Signals Maria Hybinette
“The fix” • The BSD 4.X Signal Environment • BSD developers modified the signal-handling semantics somewhat: • Signals are blocked for the duration of a signal handler (i.e. recursive signals are not normally allowed). • A "signal mask" can be set to block most signals during critical regions. • Signal handlers normally remain installed during and after signal delivery. • A separate signal handler stack can be used if desired. • Most system calls are restarted following delivery of a signal. UNIX System Programming: Signals Maria Hybinette
More details … • http://www.tutorialized.com/view/tutorial/Unix-Signals-Programming/42401 • http://web.eecs.utk.edu/~huangj/cs360/360/notes/Setjmp/lecture.html • http://www.cs.ucsb.edu/~almeroth/classes/W99.276/assignment1/signals.html UNIX System Programming: Signals Maria Hybinette