1 / 12

Inter-Process Communication: Signals

Inter-Process Communication: Signals. David Ferry, Chris Gill, Brian Kocoloski CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO 63130. Signals. Asynchronous notifications: Generated by hardware or requested by another process

eshana
Download Presentation

Inter-Process Communication: Signals

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. Inter-Process Communication:Signals David Ferry, Chris Gill, Brian Kocoloski CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO 63130

  2. Signals Asynchronous notifications: • Generated by hardware or requested by another process • Delivered to a specific process • Processes receivesignals and respond Allows for event based programming and graceful handling of errors Conceptually is very similar to hardware interrupts and exceptions, but for processes CSE 522S – Advanced Operating Systems

  3. Common Signals • SIGINT – keyboard interrupt (CTRL+C) • SIGTERM – terminate program • SIGKILL – kill program immediately • SIGSEGV – segmentation fault • SIGUSR1 & SIGUSR2 Allows for the delivery of notifications, but not for delivery of data CSE 522S – Advanced Operating Systems

  4. Signal Handler Example #include <signal.h> void sigusr1_handler( intsignum ){ //Handle signal } int main( intargc, char* argv[]){ //Normal program flow } CSE 522S – Advanced Operating Systems

  5. Signal Example Process B: context switch context switch sigusr1_handler(); Process A: Executes codeEvent happens kill( B, SIGUSR1); context switch Kernel sends signal context switch CSE 522S – Advanced Operating Systems

  6. Kernel Implementation A B kill(B, SIGUSR1) User Kernel CSE 522S – Advanced Operating Systems

  7. Kernel Implementation A B kill(B, SIGUSR1) syscall (SYS_kill,B, SIGUSR1) void sigusr1_handler (int signum) { ... } User Kernel • Find process B • Find signal handler for process B • Is signal masked? If so, save it and raise it later • Default handler? If so, terminate B • Else, raise SIGUSR1 in B CSE 522S – Advanced Operating Systems

  8. Signal Default Behaviors All signals have a default action. E.g.: • SIGTERM – terminate program • SIGCHLD – ignore signal See man 7 signal for details… Special signals that cannot be caught or blocked: • SIGKILL (force quit vs. orderly shutdown) • SIGSTOP CSE 522S – Advanced Operating Systems

  9. Signals as Hardware Events A hardware event triggers an interrupt or exception handler that raises a signal, e.g.: • Divide by zero (SIGFPE) • Segmentation fault (SIGSEGV) These are synchronous with program flow! Note: Signals allow userspace programs to respond to and correct hardware-level faults. Compare to how page faults are handled entirely within the kernel. CSE 522S – Advanced Operating Systems

  10. Concurrency Race Example int temp; void swap(int *a, int *b){ temp = *a; *a = *b; *b = temp; } void sig_handler( int signum ){ int v1 = 5, v2 = 10; swap(&v1, v2); } int main(intargc, char ** argv) { int c1 = 50, c2 = 100; sigaction(…., SIGUSR1,…); swap(&c1, &c2); } What values will v1, v2, c1, c2 have if sig_handlerand main both run once? CSE 522S – Advanced Operating Systems

  11. Signal Handler Concurrency A signal handler may be called at any point of execution! Creates a concurrent programming problem even in single threaded programs! • Deadlock • Races • Many of the same risks/strategies of interrupt handlers apply here CSE 522S – Advanced Operating Systems

  12. Today’s Studio • Register custom signal handler • Catch keyboard interrupts (CTRL+C) • Explore non-determinism resulting from signal handling CSE 522S – Advanced Operating Systems

More Related