Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.

Slides:



Advertisements
Similar presentations
Recitation 8: 10/28/02 Outline Processes Signals –Racing Hazard –Reaping Children Annie Luo Office Hours: Thursday 6:00.
Advertisements

15-213, Fall 06 Outline Shell Lab Processes Signals.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Page 1 Task Control: Signals and Alarms Havilland and Salama’s Unix Systems Programming B. Ramamurthy.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
CS Lecture 17 Outline Named pipes Signals Lecture 17
Signals Hua LiSystems ProgrammingCS2690Signals. Topics: Sending Signals -- kill(), raise() Signal Handling -- signal() sig_talk.c -- complete example.
Operating Systems Course Hebrew University Spring 2007 Signals & User Thread.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
1 Signals COS Goals of Today’s Lecture Overview of signals  Notifications sent to a process  UNIX signal names and numbers  Ways to generate.
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
Signal Signal : - is a notification sent to a process to notify it of some event - interrupts whatever the process is doing and force it to handle a signal.
Section A (March 14) Outline Exceptions Process Signals Non-local jumps Reminders Lab4: Due Next Thursday TA: Kun Gao Shamelessly Modified from Minglong.
Signals, Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
B. RAMAMURTHY Pag e 1 Task Control: Signals and Alarms Chapter 7 and 8 7/2/2015.
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
COMP5102 Lecture 4 Operating Systems (OS) Inter-process Communication phones off (please)
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Signals & Timers CS241 Discussion Section Spring 2009 Week 6.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks II.
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
Operating Systems CSE 411 CPU Management Sept Lecture 9 Instructor: Bhuvan Urgaonkar.
* POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm Topics.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R S I X Exception Handling.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
Washington WASHINGTON UNIVERSITY IN ST LOUIS Core Inter-Process Communication Mechanisms (Historically Important) Fred Kuhns
UNIX Socket Programming CS 6378 Project Reference Book: Unix Network programming: Networking APIs: Sockets and XTI (2nd edition), Prentice Hall >> Threads.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks II.
Signals and Signal Processing CIS 370 Lab 7 Umass Dartmouth.
Signals and Signal Handling. Signals A predefined message sent between two processes or from the kernel to a process, or by a user to a process A software.
Signals (Chap 10 in the book “Advanced Programming in the UNIX Environment”) Acknowledgement : Prof. Y. Moon at Kangwon Nat’l Univ.
NCHU System & Network Lab Lab #8 Signals Operating System Lab.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
SignalsSignals. What is a Signal? A signal is a notification that some event has occurred. Usually a signal is sent to a process asynchronously and whatever.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
UNIX signals & pipes. UNIX Signals A UNIX signal corresponds to an event –It is raised by one process (or hardware) to call another process’s attention.
Operating Systems Recitation 4, April th, 2002 Signals.
Signals. Introduction r A signal is a mechanism for notifying a process that an event has occurred. m When a signal is sent to a process is normal execution.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
1 UNIX System Programming Signals. 2 Overview 1. Definition 2. Signal Types 3. Generating a Signal 4. Responding to a Signal 5. Common Uses of Signals.
KUKUM Real Time System Module #3 POSIX programming Lecture 2.
© 숙대 창병모 1 제 10 장 신호 (Signal). © 숙대 창병모 2 Contents 1. Signal Concepts 2. signal() 3. Interrupted System Calls 4. kill() /raise() 5. alarm() pause() 6.
Today’s topic Environment variables Signal. The list of environment variables –try ‘env’ –Environment variables can be defined in shell setenv DISPLAY.
Carnegie Mellon 1 Processes, Signals, I/O, Shell Lab : Introduction to Computer Systems Recitation 9: Monday, Oct. 21, 2013 Marjorie Carlson Section.
Chapter 8 Signals Source: Robbins and Robbins, UNIX Systems Programming, Prentice Hall, 2003.
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
Signals & Message queue Inter process mechanism in Linux system 3/24/
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Signals.
Operating Systems Practical Session 3, Signals 1.
Operating Systems Inter-Process Communication Signals Moti Geva
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
UNIX signals.
G.Jyostna.
Task Control: Signals and Alarms Chapter 7 and 8
Unix Process Management
Tarek Abdelzaher Vikram Adve Marco Caccamo
CSC Advanced Unix Programming, Fall 2015
Signals Tanzir Ahmed CSCE 313 Fall 2018.
Inter-Process Communication ENCE 360
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Signals.
Presentation transcript:

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals

Copyright ©: Nahrstedt, Angrave, Abdelzaher 2 Posix Signals Signals are an integral part of multitasking in the UNIX/POSIX environment. Signals are used for many purposes, including: 1. Exception handling (bad pointer accesses, divide by zero, etc.) 2. Process notification of asynchronous event occurrence (I/O completion, timer expiration, etc.) 3. Process termination in abnormal circumstances 4. Interprocess communication Signals are similar to the notion of hardware interrupts. However, they are managed and delivered by the Operating System.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 3 Dealing with signals There are different ways in which you can deal with a signal: 1. You can block a signal for a while, and get to it (by unblocking it) later. Blocking signals is a temporary measure. 2. You can ignore the signal, in which case it is as if the signal never arrived. 3. You can handle the signal by executing a default action to deal with the signal (the default action often is to kill the process receiving the signal) 4. You can handle the signal by setting up a function to be called whenever a signal with a particular number arrives. There are two spare signals available to user applications: SIGUSR1 and SIGUSR2. Any application can use them as it wants.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 4 Basic Signal Concepts Signal is generated when the event that causes it occurs. Signal is delivered when a process receives it. The lifetime of a signal is the interval between its generation and delivery. Signal that is generated but not delivered is pending. Process catches signal if it executes a signal handler when the signal is delivered. Alternatively, a process can ignore a signal when it is delivered, that is to take no action. Process can temporarily prevent signal from being delivered by blocking it. Signal Mask contains the set of signals currently blocked.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 5 Steps of Signal’s Delivery and Handling Event of sending a signal: 1. The OS updates the descriptor of the destination process to represent that a new signal has been sent. 2. Signals that have been sent but not yet received are called pending signals. At any time, only one pending signal of a given type may exist for a process; additional pending signals of the same type to the same process are not queued but simply discarded. Signal sent by the OS or by a process Process mask Signal received by the current executing process when switching from Kernel Mode to User Mode signal pending ignore signal default action user’s handler signal received

Copyright ©: Nahrstedt, Angrave, Abdelzaher 6 Steps of Signal’s Delivery and Handling Event of receiving a signal: 1. If the sent signal is blocked by the process mask, the process will not receive the signal until it removes the block: the signal remains pending. 2. When switching from Kernel Mode to User Mode, check whether a signal has been sent to the current executing process (this happens at every timer interrupt). Unblocked signals are received. 3. Determine whether ignore the signal, execute a default action or execute user’s signal handler. Signal sent by the OS or by a process Process mask Signal received by the current executing process when switching from Kernel Mode to User Mode signal pending ignore signal default action user’s handler signal received

Copyright ©: Nahrstedt, Angrave, Abdelzaher 7 How Signals Work Signal Generated Process Signal Handler Signal delivered Signal not blocked Signal Caught by handler Return from Signal Handler Process Resumed Process Signal Mask Handler signal Mask Process Signal Mask A signal handler interacts with the regular execution flow of the corresponding process by simply sharing global variables: the regular execution flow and signal handler execute in the same memory space.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 8 Examples of POSIX Required Signals SignalDescriptiondefault action SIGABRTprocess abortimplementation dependent SIGALRMalarm clockabnormal termination SIGBUSaccess undefined part of memory objectimplementation dependent SIGCHLDchild terminated, stopped or continuedignore SIGILLinvalid hardware instructionimplementation dependent SIGINTinteractive attention signal (usually ctrl-C) abnormal termination SIGKILLterminated (cannot be caught or ignored) abnormal termination

Copyright ©: Nahrstedt, Angrave, Abdelzaher 9 SignalDescriptiondefault action SIGSEGVInvalid memory referenceimplementation dependent SIGSTOPExecution stoppedstop SIGTERMterminationAbnormal termination SIGTTINBackground process attempting readstop SIGTTOUBackground process attempting writestop SIGURGHigh bandwidth data available on socket ignore SIGUSR1User-defined signal 1abnormal termination Examples of POSIX Required Signals

Copyright ©: Nahrstedt, Angrave, Abdelzaher 10 Signal Masks Process can temporarily prevent signal from being delivered by blocking it. Signal Mask contains a set of signals currently blocked. Important!  Blocking a signal is different from ignoring signal. Why?

Copyright ©: Nahrstedt, Angrave, Abdelzaher 11 Signal Masks Process can temporarily prevent signal from being delivered by blocking it. Signal Mask contains a set of signals currently blocked. Important!  Blocking a signal is different from ignoring signal. Why? When a process blocks a signal, the OS does not deliver signal until the process unblocks the signal When a process ignores signal, signal is delivered and the process handles it by throwing it away.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 12 Signal Sets Signal set is of type sigset_t Signal sets are manipulated by five functions: #include int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo); int sigismember(const sigset_t *set, int signo);

Copyright ©: Nahrstedt, Angrave, Abdelzaher 13 Signal Sets sigemptyset initializes the set to contain no signals sigfillset puts all signals in the set sigaddset adds one signal to the set sigdelset removes one signal from the set sigismember tests to see if a signal is in the set

Copyright ©: Nahrstedt, Angrave, Abdelzaher 14 Example: Initialize Signal Set: if ((sigemptyset(&twosigs) == -1) || (sigaddset(&twosigs, SIGINT) == -1) || (sigaddset(&twosigs, SIGQUIT) == -1)) perror("Failed to set up signal mask");

Copyright ©: Nahrstedt, Angrave, Abdelzaher 15 Setting the Signal Mask of a process The collection of signals that are currently blocked is called the signal mask. Each process has its own signal mask. When you create a new process, it inherits its parent's mask. You can block or unblock signals with total flexibility by modifying the signal mask

Copyright ©: Nahrstedt, Angrave, Abdelzaher 16 Function: int sigprocmask (int how, const sigset_t *set, sigset_t *oldset) The sigprocmask function is used to examine or change the calling process's signal mask. The how argument determines how the signal mask is changed, and must be one of the following values: SIG_BLOCK Block the signals in set---add them to the existing mask. In other words, the new mask is the union of the existing mask and set. SIG_UNBLOCK Unblock the signals in set---remove them from the existing mask. SIG_SETMASK Use set for the mask; ignore the previous value of the mask. The last argument, oldset, is used to return information about the old process signal mask Setting the Signal Mask of a process

Copyright ©: Nahrstedt, Angrave, Abdelzaher 17 Example: Add SIGINT to Set of Blocked Signals sigset_t newsigset; if ((sigemptyset(&newsigset) == -1) || (sigaddset(&newsigset, SIGINT) == -1)) perror("Failed to initialize the signal set"); else if (sigprocmask(SIG_BLOCK, &newsigset, NULL) == -1) perror("Failed to block SIGINT"); If SIGINT is already blocked, the call to sigprocmask has no effect.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 18 Generating Signals Signals have a symbolic name starting with SIG Signal names are defined in signal.h Users can generate signals (e.g., SIGUSR1) OS generates signals when certain errors occur (e.g., SIGSEGV – invalid memory reference) Specific calls generate signals such as alarm (e.g., SIGALARM)

Copyright ©: Nahrstedt, Angrave, Abdelzaher 19 Command Line Generates Signals You can send a signal to a process from the command line using kill kill -l will list the signals the system understands kill [-signal] pid will send a signal to a process. The optional argument may be a name or a number (default is SIGTERM). To unconditionally kill a process, use: kill -9 pid which is kill -SIGKILL pid.

Copyright ©: Nahrstedt, Angrave, Abdelzaher 20 Examples: Programming Signals From a program you can use the kill system call: #include int kill(pid_t pid, int sig); Example 8.4: send SIGUSR1 to process 3423: if (kill(3423, SIGUSR1) == -1) perror("Failed to send the SIGUSR1 signal"); Example 8.5: a child kills its parent: if (kill(getppid(), SIGTERM) == -1) perror ("Failed to kill parent");

Copyright ©: Nahrstedt, Angrave, Abdelzaher 21 Command Line Generates Signals CTRL-C is SIGINT (interactive attention signal CTRL-Z is SIGSTOP (execution stopped – cannot be ignored) CTRL-Y is SIGCONT (execution continued if stopped)

Copyright ©: Nahrstedt, Angrave, Abdelzaher 22 Timers Generate SIGALRM Signals #include unsigned alarm (unsigned seconds); alarm(20) creates SIGALRM to calling process after 20 real time seconds. Alarm requests are not stacked; only one SIGALRM generation can be scheduled in this manner. If the SIGALRM signal has not yet been generated, calling alarm() again will reschedule the time at which the SIGALRM signal is generated. alarm(0) cancels alarm