1 / 11

UNIX System Programming

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:

yosefu
Download Presentation

UNIX System Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIX System Programming Signals: Wrap-up

  2. 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

  3. 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

  4. 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

  5. Common Signals UNIX System Programming: Signals Maria Hybinette

  6. Common Signals, continued UNIX System Programming: Signals Maria Hybinette

  7. 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

  8. 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

  9. 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

  10. “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

  11. 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

More Related