Outline. Signal Names and Types. What is a Signal? CSCI 4061 Introduction to Operating Systems

Similar documents
INTER-PROCESS COMMUNICATION AND SYNCHRONISATION: Lesson-12: Signal Function

Tebis application software

Solved MCQS From Midterm Papers. MIDTERM EXAMINATION Spring CS604 - Operating System

)454 ( ! &!2 %.$ #!-%2! #/.42/, 02/4/#/, &/2 6)$%/#/.&%2%.#%3 53).' ( 42!.3-)33)/. /&./.4%,%0(/.% 3)'.!,3. )454 Recommendation (

Good afternoon! My name is Swetha Mettala Gilla you can call me Swetha.

ORM0022 EHPC210 Universal Controller Operation Manual Revision 1. EHPC210 Universal Controller. Operation Manual

XYZ Cinemas - ecna Configuration 12/12/2013 Table of Contents

Solved MCQS From Midterm Papers. MIDTERM EXAMINATION Spring CS604 - Operating System

ECT 224: Digital Computer Fundamentals Digital Circuit Simulation & Timing Analysis

SIDRA INTERSECTION 8.0 UPDATE HISTORY

Laboratory Exercise 4

VAD Mobile Wireless. OBD-II User's Manual Version 1.0

Using ADC and QADC Modules with ColdFire Microcontrollers The MCF5211/12/13 and MCF522xx ADC Module The MCF5214/16 and MCF528x QADC Module

Linux-based Mobile Phone Middleware. Application Programming Interface. Circuit-Switched Communication Service. Document: CELF_MPP_CS_D_FR4

Digital Video Recorder From Waitsfield Cable

DXI SAC Software: Configuring a CCTV Switcher. Table of Contents

USER S GUIDE. 1 Description PROGRAMMABLE 3-RELAY LOGIC MODULE

Linux based 3G Specification. Multimedia Mobile Phone API. Circuit Switched Communication Service. Document: CELF_MPP_CS_FR2b_

Provides an activation of Relay 1 triggered by Input 1. The function also provides an option for reverse-logic on the activation of Input 1.

Documentation EL6900-FB, KL6904-FB. TwinCAT function blocks for TwinSAFE logic terminals. Version: Date:

KNX / EIB Product Documentation. DALI Gateway. Date of issue: Order no Page 1 of 136

Digital Video User s Guide THE FUTURE NOW SHOWING

KL6904-FB. Documentation for TwinCAT function blocks of the TwinSAFE KL6904 Logic Terminal

Application of A Disk Migration Module in Virtual Machine live Migration

PRODUCT MANUAL LUMENTO X3 LED. LED Controller ZN1DI-RGBX3. Program Version: 1.0 Manual Edition: a

ECE 4220 Real Time Embedded Systems Final Project Spectrum Analyzer

DX100 OPTIONS INSTRUCTIONS

ENGINEERING COMMITTEE Energy Management Subcommittee SCTE STANDARD SCTE

CI-218 / CI-303 / CI430

SPIRIT. SPIRIT Attendant. Communications System. User s Guide. Lucent Technologies Bell Labs Innovations

Digilent Nexys-3 Cellular RAM Controller Reference Design Overview

welcome to i-guide 09ROVI1204 User i-guide Manual R16.indd 3

Instruction manual. DALI Gateway art Installation manual

FSM Cookbook. 1. Introduction. 2. What Functional Information Must be Modeled

Video Storage in Ocularis

Dimming actuators GDA-4K KNX GDA-8K KNX

BASIC CLINICAL TRAINING

CDV07. Analog video distribution amplifier(s)

application software

TERRA. DVB remultiplexer TRS180. User manual

IP LIVE PRODUCTION UNIT NXL-IP55

TV About TV Watching TV Recording/Playing Programs View/Record Timer Advanced Features

EECS150 - Digital Design Lecture 10 - Interfacing. Recap and Topics

Operations. BCU Operator Display BMTW-SVU02C-EN

Tebis application software

Refer to the included CD-ROM for the German, French, Spanish and Italian Manual for Remote Operation by Network Connection. Die Bedienungsanleitung

Digital Video User s Guide THE FUTURE NOW SHOWING

013-RD

Dimming actuators of the FIX series DM 4-2 T, DM 8-2 T

FACILITIES STUDY MID AMERICAN TRANSMISSION SERVICE REQUESTS. OASIS Revision: 4

Reno A & E, 4655 Aircenter Circle, Reno, NV (775)

User s Manual. Network Board. Model No. WJ-HDB502

Asynchronous counters

HW#3 - CSE 237A. 1. A scheduler has three queues; A, B and C. Outgoing link speed is 3 bits/sec

RS-232C External Serial Control Specifications

Instruction Level Parallelism Part III

SECURITRON PRIME TIME MODEL DT-7 INSTALLATION AND OPERATING INSTRUCTIONS

Training Note TR-06RD. Schedules. Schedule types

MICROMASTER Encoder Module

ST10F273M Errata sheet

OMA Device Management Server Delegation Protocol

DNA-STP-SYNC Synchronization and Screw Terminal Panel. User Manual

You will be first asked to demonstrate regular operation with default values. You will be asked to reprogram your time values and continue operation

ANSI/SCTE

Instruction Level Parallelism Part III

Cisco Spectrum Expert Software Overview

DX-TL1600EM DIGITAL RECORDER INSTALLATION AND OPERATION MANUAL MODEL ENGLISH DEUTSCH FRANÇAIS CASTELLANO OTHERS

ICA - Interaction and Communication Assistant

Conference Speaker Timing System. Operating Instruction Manual

Digital Video User s Guide THE FUTURE NOW SHOWING

DAC20. 4 Channel Analog Audio Output Synapse Add-On Card

application software

RADview-PC/TDM. Network Management System for TDM Applications Megaplex RAD Data Communications Publication No.

OPERATION MANUAL. USF-1013DEMUX Digital Audio Demultiplexer. 2 nd Edition. Software Version Higher

DigiPoints Volume 2. Student Workbook. Module 5 Headend Digital Video Processing

REVISIONS LTR DESCRIPTION DATE APPROVED - Initial Release 11/5/07 MDB A ECR /9/08 MDB

Device Management Requirements

EECS 373 Design of Microprocessor-Based Systems

MELSEC iq-r Temperature Control Module User's Manual (Application) -R60TCTRT2TT2 -R60TCTRT2TT2BW -R60TCRT4 -R60TCRT4BW

AVR065: LCD Driver for the STK502 and AVR Butterfly. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Digital Video User s Guide

Subtitle Safe Crop Area SCA

Design and Use of a DTV Monitoring System consisting of DVQ(M), DVMD/DVRM and DVRG

DMX-LINK QUICK OPERATION

User s handbook ASI TRANSPARENT MULTIPLEXER/DEMULTIPLEXER. EK-MPA/4 & EK-DMA/4 boards

Digital Electronics Course Outline

Noise Detector ND-1 Operating Manual

Operations of ewelink APP

Introduction to Computers and Programming

3200NT System 14. Service Manual. IMPORTANT: Fill in Pertinent Information on Page 3 for Future Reference

Chapter 5 Sequential Circuits

Modbus for SKF IMx and Analyst

User's Guide. Version 2.3 July 10, VTelevision User's Guide. Page 1

COMPUTER ENGINEERING PROGRAM

Hardware & software Specifications

Watchman. Introduction: Door Lock Mobile MAX

Event Triggering Distribution Specification

OPERATION AND MAINTENANCE

VISSIM TUTORIALS This document includes tutorials that provide help in using VISSIM to accomplish the six tasks listed in the table below.

Classroom Setup... 2 PC... 2 Document Camera... 3 DVD... 4 Auxiliary... 5

Transcription:

Outline CSCI 4061 Introduction to Operating Systems Signal Overview Signal Generation and Handling Signal Safety Realtime Signals Instructor: Abhishek Chandra 2 What is a Signal? Signal Names and Types A software interrupt generated by the OS or processes In response to an asynchronous event Exception or error. E.g.: Bad memory access, divide-by-zero OS notification of an event. E.g.: Alarm, child process termination, async-i/o completion Generated by the user/another process. E.g.: Ctrl-C, process stop, user-specified signal Each signal has a name Starts with SIG E.g.: SIGALRM, SIGSEGV, SIGKILL Each signal name corresponds to a specific event type. Examples: SIGCHLD: Child terminated SIGSEGV: Segmentation fault SIGKILL: Kill signal SIGPIPE: Writing to a pipe with no readers SIGINT: Interrupt key input (typically Ctrl-C) 3 4 1

Signal Generation and Delivery A signal is generated when an event occurs E.g.: When user presses Ctrl-C Could be generated by the OS or by another process Signal is delivered when the process takes action Process must be running to get signal delivery Signal is pending between its generation and delivery Only one instance of a signal remains pending Multiple undelivered instances are combined Generating Signals: kill int kill(pid_t pid, int sig); Sends a signal to another process pid: Signal-receiving process Sender should have appropriate permissions sig: Signal name kill command kill s signal_name pid E.g.: kill s USR1 1234 5 6 Handling Signals A process can take one of multiple actions Ignore: Throw away the signal Cannot ignore SIGKILL and SIGSTOP Block: Delay the delivery of the signal Unblocking delivers a pending signal Cannot block SIGKILL and SIGSTOP Catch: Set up a user function to be called when the signal is delivered Default Action Depends on signal type Most signals result in process termination Some are ignored by default (e.g.: SIGCHLD) 7 8 2

Blocking Signals A signal can be blocked Is not delivered to process Remains in pending state Delivered to process upon unblocking Why block signals? To avoid being interrupted by unexpected signals E.g.: in the middle of a critical section Blocking Signals: Signal Masks and Sets Signal mask: Set of signals that are currently blocked by a process Manipulated using signal set (type sigset_t) Operations: sigaddset: Add a signal to the set sigdelset: Remove a signal from the set sigismember: Check if a signal is in the set sigemptyset: Clear all signals in the set sigfillset: Set all signals in the set 9 10 Manipulating Signal Masks int sigprocmask(int how, sigset_t *set, sigset_t *old_set); Manipulates the signal mask (set of blocked signals) how: How the signal mask would be modified SIG_BLOCK: Add a set of signals for blocking SIG_UNBLOCK: Unblock a set of signals SIG_SETMASK: Set current signal mask to given signal set set: Signal set to be used for manipulation old_set: The old signal mask before modification Signal Blocking Example sigset_t newsigset, oldsigset; /* Add SIGINT to the new signal set */ sigemptyset(&newsigset); sigaddset(&newsigset, SIGINT); /* Add SIGINT to the set of blocked signals */ sigprocmask(sig_block, &newsigset, &oldsigset); /* Check if SIGQUIT is in the old signal mask */ if (sigismember(&oldsigset, SIGQUIT)) printf( SIGQUIT already blocked\n ); 11 12 3

Catching Signals A signal can be caught A user-defined function is called upon signal delivery To catch a signal: Define a signal handler function Set up the signal to be caught and signal handler to be called Why catch signals? May want user to take meaningful action for specific events E.g.: do something when an alarm goes off Signal Handler User-defined function called when signal is delivered Syntax: void (*sa_handler)(int) Argument is set to the signal number being delivered Does not allow passing other parameters Realtime signal handler is more versatile Can also specify: SIG_DFL: Default action SIG_IGN: Ignore action 13 14 Catching Signals: sigaction int sigaction(int sig, struct sigaction *action, struct sigaction *old_action); Specifies the action to take for a signal sig: Name of the signal action: Action to be taken old_action: The previous action associated with the signal Specifying the Action struct sigaction sa_handler: Signal handler sa_mask: Additional signals to be blocked in the signal handler sa_flags: Special flags and options sa_sigaction: Realtime signal handler Only one of sa_handler and sa_sigaction can be specified 15 16 4

Signal Catching Example /* Signal handler */ void myhandler(int signo) { printf( Received signal: %d\n, signo); } struct sigaction newact; newact.sa_handler = myhandler; /* Set sig handler */ sigemptyset(&newact.sa_mask); /* No other signals to be blocked */ newact.sa_flags = 0; /* No special options */ /* Install the signal handler for SIGINT */ sigaction(sigint, &newact, NULL); Waiting for Signals Signals can be used to wait for a specific event without busy waiting Approach 1: Set a signal handler for a specific signal and wait until the signal is caught pause sigsuspend Approach 2: Block a signal and wait for signal to be generated sigwait 17 18 Waiting for Signals: pause int pause(void); Wait until a signal arrives Returns after the return of signal handler Have to check which signal arrived No way to ensure that signal does not arrive before calling pause Would like to: Block the desired signal until pause Unblock it immediately before calling pause Waiting for Signals: sigsuspend int sigsuspend(sigset_t *sigmask); Change signal mask and wait until a signal arrives Operations done atomically Signals in sigmask are blocked Signal mask used to atomically unblock the signal to be caught Remove desired signal from the signal mask 19 20 5

Waiting for Signals: sigwait int sigwait(sigset_t *set, int *signo); Waits for a set of signals Returns when one of the signals becomes pending Removes it from set of pending signals set: Set of signals to wait for signo: Contains the signal number on return Main Differences: No signal handler used Desired signals should be blocked before calling sigwait Signal Safety Problems Signals are asynchronous Can arrive in the middle of a function Signal handler can be executed concurrently Some library functions are not async-signal safe Use static/global data structures Can result in data access conflicts E.g.: strtok, perror Some blocking calls return prematurely when interrupted by signals E.g.: read, write, etc. 21 22 Ensuring Signal Safety May need to restart interrupted library calls Use async-signal safe library calls inside signal handlers Block a signal before entering critical sections that may conflict with the signal handler Similar to locking/unlocking Save and restore errno inside the signal handler Signals Summary Signals: Software interrupts Signal generation: By OS or kill function Signal handling: Default Ignore Catch with user-defined signal handler Block/unblock Signal waiting Signal safety issues 23 24 6

Limitations of Signals Multiple signals are coalesced when blocked Only one pending signal is delivered Lose multiple signals Cannot pass data to signal handlers Cannot distinguish between multiple signals No information about the signal-raising event Very few user-defined signals SIGUSR1 and SIGUSR2 No order of signal delivery Realtime Signals Allow queuing of signals Multiple signals of same type can be delivered Allow passing data with the signal Can pass the context of signal to a process Data can be received by signal handler E.g.: file descriptor on which data arrived Large number of new user-defined signals SIGRTMIN...SIGRTMAX Ordering of signal delivery Queued signals in FIFO order Priority order between RT signals 25 26 Using Realtime Signals Sender: Can enqueue multiple instances of the same signal type Can send data with the signal Can send different RT signals with different priority Receiver: Can pick up one signal instance at a time Can pick up data: catch signals using a different signal handler, or different signal waiting call Queuing Signals int sigqueue(pid_t pid, int signo, union sigval value); Queues a signal to another process Also depends on recipient s action for signal Also sends data with the signal pid: Signal-receiving process Sender should have appropriate permissions signo: Signal number value: Data passed with the signal Union of int and (void *) 27 28 7

Revisiting Signal Handlers struct sigaction sa_handler: Signal handler sa_mask: Additional signals to be blocked in the signal handler sa_flags: Special flags and options sa_sigaction: Realtime signal handler For realtime behavior: sa_flags should be set to SA_SIGINFO sa_sigaction should be set to the handler Realtime Signal Handlers void func(int signo, siginfo_t *info, void *context) : signo: Signal number info: Contains information about signal data context: Undefined 29 30 Realtime Signal Handlers void func(int signo, siginfo_t *info, void *context) siginfo_t: si_signo: Signal number (same as signo) si_code: How signal was generated By a user process using kill Using sigqueue Timer, asynchronous I/O, etc. si_value: Data generated with the signal Union of int and (void *) Realtime Signal Example: Sender int pid; union sigval value; /* Set value to send with signal */ value.sival_int = 1; /* Send signal to be queued */ sigqueue(pid, SIGRTMIN, value); 31 32 8

Realtime Signal Example: Receiver /* Signal handler */ void myhandler(int signo, siginfo_t *info, void *context) { int val = info->si_value.sival_int; printf( Signal: %d, value: %d\n, signo, val); } struct sigaction act; act.sa_sigaction = myhandler; /* Set RT sig handler */ sigemptyset(&act.sa_mask); act.sa_flags = SA_SIGINFO; /* RT sigs flag */ Waiting for RT Signals: sigwaitinfo int sigwaitinfo(sigset_t *set, siginfo_t *info); Similar to sigwait Returns when one of the signals becomes pending Removes it from set of pending signals set: Set of signals to wait for info: Contains info about signal data /* Install the signal handler for SIGRTMIN */ sigaction(sigrtmin, &act, NULL); 33 34 Realtime Signals Usage Scenarios Lightweight IPC: Processes can pass int values Timer interrupts could be sent more efficiently Multiple timer interrupts could be queued I/O multiplexing easier File descriptors could be sent with I/O ready signals Asynchronous I/O could be signaled easily Data pointer could be returned with the signal 35 9