UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *

Slides:



Advertisements
Similar presentations
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Advertisements

1 Select and poll and Signals CS 241 April 6, 2012 University of Illinois.
CS591 (Spring 2001) The Linux Kernel: Signals & Interrupts.
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
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.
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.
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.
Shells, System Calls, and Signals. What is a Shell? A shell is a command line interface to the operating system – Fetch a command from the user and execute.
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.
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
The kernel considers each program running on your system to be a process A process lives as it executes, with a lifetime that may be short or long A process.
Operating Systems CSE 411 CPU Management Sept Lecture 9 Instructor: Bhuvan Urgaonkar.
1GWU CS 259 Brad Taylor Spring 2004 Systems Programming Meeting 5: Signals, Time, Timers, and Token Rings.
* POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm Topics.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
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.
Signals (Chap 10 in the book “Advanced Programming in the UNIX Environment”) Acknowledgement : Prof. Y. Moon at Kangwon Nat’l Univ.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
UNIX Socket Programming CS 6378 Project Reference Book: Unix Network programming: Networking APIs: Sockets and XTI (2nd edition), Prentice Hall >> Threads.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Signals and Signal Processing CIS 370 Lab 7 Umass Dartmouth.
Outline for Today Objectives –Finish discussion of Birrell –UNIX Signals –Eraser Administrative –Spider talk after class.
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.
Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.
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.
CSC Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 22, class 5.
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.
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
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)
Signals and daemon processes Prepared by : Department of CSE Engineered for Tomorrow Course code: 10CS62.
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.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.
Operating Systems Practical Session 3, Signals 1.
Operating Systems Inter-Process Communication Signals Moti Geva
UNIX signals.
Signals What is a Signal?
Task Control: Signals and Alarms Chapter 7 and 8
Protection of System Resources
Unix Process Management
UNIT-IV Process and Signals
Shells, System Calls, and Signals
CSC Advanced Unix Programming, Fall 2015
Signals Tanzir Ahmed CSCE 313 Fall 2018.
Inter-Process Communication ENCE 360
Task Control: Signals and Alarms Chapter 7 and 8
CSE 451: Operating Systems Spring 2006 Module 4 Processes
Signals.
Presentation transcript:

UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers * timer Class

POSIX-Defined Signals (1) * SIGALRM: Alarm timer time-out. Generated by alarm( ) API. * SIGABRT: Abort process execution. Generated by abort( ) API. * SIGFPE: Illegal mathematical operation. * SIGHUP: Controlling terminal hang-up. * SIGILL: Execution of an illegal machine instruction. * SIGINT: Process interruption. Can be generated by or keys. * SIGKILL: Sure kill a process. Can be generated by “kill -9 “ command. * SIGPIPE: Illegal write to a pipe. * SIGQUIT: Process quit. Generated by keys. * SIGSEGV: Segmentation fault. generated by de-referencing a NULL pointer.

POSIX-Defined Signals (2) * SIGTERM: process termination. Can be generated by “kill ” command. * SIGUSR1: Reserved to be defined by user. * SIGUSR2: Reserved to be defined by user. * SIGCHLD: Sent to a parent process when its child process has terminated. * SIGCONT: Resume execution of a stopped process. * SIGSTOP: Stop a process execution. * SIGTTIN: Stop a background process when it tries to read from from its controlling terminal. * SIGTSTP: Stop a process execution by the control_Z keys. * SIGTTOUT: Stop a background process when it tries to write to its controlling terminal.

Signaling Processes * Signal A signal is a notification to a process that an event has occurred. Signals are sometimes called “software interrupts”. * Features of Signal - Signal usually occur asynchronously. - The process does not know ahead of time exactly when a signal will occur. - Signal can be sent by one process to another process (or to itself) or by the kernel to a process.

Sources for Generating Signals * Hardware - A process attempts to access addresses outside its own address space. - Divides by zero. * Kernel - Notifying the process that an I/O device for which it has been waiting is available. * Other Processes - A child process notifying its parent process that it has terminated. * User - Pressing keyboard sequences that generate a quit, interrupt or stop signal.

Three Courses of Action Process that receives a signal can take one of three action: * Perform the system-specified default for the signal - notify the parent process that it is terminating; - generate a core file; (a file containing the current memory image of the process) - terminate. * Ignore the signal A process can do ignoring with all signal but two special signals: SIGSTOP and SIGKILL. * Catch the Signal When a process catches a signal, except SIGSTOP and SIGKILL, it invokes a special signal handing routine.

sigprocmask API - Signal Mask (1) * Function A process can query or set its signal mask via the sigprocmask API. * Include: * Summary: int sigprocmask ( int cmd, cost sigset_t *new_mask, sigset_t *old_mask); * Return: Success: 0 Failure: -1 Sets errno: Yes

Arguments of sigprocmask API - Signal Mask (2) * new_mask: defines a set of signals to be set or reset in a calling process signal mask. new_mask = NULL, current process signal mask unaltered. * cmd: specifies how the new_mask value is to be used: - SIG_SETMASK: Overrides the calling process signal mask with the value specified in the new_mask argument. - SIG_BLOCK: Adds the signals specified in the new_mask argument to the calling process signal mask. - SIG_UNBLOCK: Removes the signals specified in the new_mask argument from the calling process signal mask * old_mask: Address of a sigset_t variable that will be assigned the calling processing’s original signal mask. old_mask = NULL, no previous signal mask will be return.

sigsetops APIs - Signal Mask (3) * int sigemptyset (sigset_t* sigmask); Clears all signal flags in the sigmask argument. * int sigaddset (sigset_t* sigmask, const int signal_num); Sets the flag corresponding to the signal_num signal in the sigmask argument. * int sigdelset (sigset_t* sigmask, const int signal_num); Clears the flag corresponding to the signal_num signal in the sigmask argument. * int sigfillset(sigset_t* sigmask); Sets all the signal flags in the sigmask argument. * int sigismember(const sigset_t* sigmask,const int signal_num); Returns 1 if the flag corresponding to the signal_num signal in the sigmask argument is set; zero: not set; -1: the call fails.

sigprocmask Example - Signal Mask (4) /* The example checks whether the SIGINT signal is present in a process signal mask and adds it to the mask if it is not there. It clears the SIGSEGV signal from the process signal mask. */ int main( ){ sigset_tsigmask; sigemptyset(&sigmask);/*initialize set */ if(sigprocmask(0,0,&sigmask)==-1)/*get current signal mask*/ {perro(“sigprocmask”); exit(1); } else sigaddset(&sigmask, SIGINT); /* set SIGINT flag*/ sigdelset(&sigmask, SIGSEGV); /* clear SIGSEGV flag */ if (sigprocmask(SIG_SETMASK,&sigmask,0) == -1) perro(“sigprocmask”); /* set a new signal mask */ }

sigpending API- Signal Mask (5) * Function The sigpending API can find out whether one or more signals are pending for a process and set up special signal handing methods for those signals before the process calls the sigprocmask API to unblock them. * Include: * Summary: int sigpending (sigset_t* sigmask); * Return: Success: 0; Failure: -1; Sets errno: Yes * Argument sigmask argument, to the sigpending API, is the address of a sigset_t-type variable and is assigned the set of signals pending for the calling process by the API.

sigpending Example - Signal Mask (6) /* The example reports to the console whether the SIGTERM signal is pending for the process. */ int main ( ) { sigset_tsigmask; sigemptyset(&sigmask); /* initialize set */ if (sigpending(&sigmask) == -1) /* Any signal is pending */ perro(“sigpending”); else cout<<”SIGTERM signal is:” << (sigismember (&sigmask,SIGTERM) ? “Set” : “No Set”); /* whether SIGTERM signal in the sigmask argument is set? */

sigaction API - sigaction (1) * Function.The sigaction API setups a signal handling method for each signal it wants to deal with and passes back the previous signal handling method for a given signal. The sigaction API blocks the signal it is catching allowing a process to specify additional signals to be blocked when the API is handling a signal. * Include: * Summary: int sigaction ( int signal_num, struct sigaction* action, struct sigaction* old_action); * Return: Success: 0; Failure: -1; Sets errno: Yes

struct sigaction - sigaction (2) * struct sigaction { void(*sa_handler) (int); sigset_tsa_mask; intsa_flag; } * sa_handler is the function point of a user-defined signal handler function, SIG_IGN (ignores a signal), or SIG_DFL (accepts the default action of a signal). * sa_mask specifies additional signals that a process wishes to block when it is handling the signal_num signal. * sa_flag specifies special handling for certain signals.

sa_flag value - sigaction (3) 0:when the signal_num is SIGCHLD, the kernel will send the SIGCHLD signal to the calling process whenever its child process is either terminated or stopped. SA_NOCLDSTOP: when the signal_num is SIGCHLD, the kernel will generate the SIGCHLD signal to the calling process whenever its child process is either terminated, but not when the child process has been stopped. SA_RESETHAND: If signal_num is caught, the sa_handler is set to SIG_DFL before the signal handler function is called, and signal_num will not be added to the process signal mask SA_RESTART: If a signal is caught while a process is executing a system call, the kernel will restart the system call after the signal handler returns. If this flag is not set in the sa_flag, after the signal handler returns, the system call will be aborted with a return value of -1 and will set errno to EINTR (aborted due to a signal interruption).

Arguments of sigaction - sigaction (4) * signal_num The signal_num argument designates which signal handling action is defined in the action argument. * old_action The previous signal handling method for signal_num will be returned via the old_action argument if it is not a NULL pointer. * action action argument sets up a signal handling method for the signal_num argument. If the action argument is a NULL pointer, the calling process’s existing signal handling method for signal_num will be unchanged. ! Example: sigaction.C

kill API - kill and sigaction(1) * Function - A process can send a signal to a related process via the kill API. - This is a simple means of interprocess communication or control. - The sender and recipient processes must be related such that either the sender process real or effective user ID matches that of the recipient process, or the sender process has superuser privileges. * Include: * Summary: int kill ( pid_t pid, int signal_num); * Return: Success: 0; Failure: -1; Sets errno: Yes

Arguments of kill - kill and sigaction (2) *int signal_num: the integer value of a signal to be sent to one or more processes designated by pid. *pid_t pid value - positive value: pid is process ID. Sends signal_num to that process. - 0: sends signal_num to all process whose group ID is the same as the calling process. - -1: Sends signal_num to all processes whose real user ID is the same as the effective user ID of the calling process. Example: killpipe.c

alarm API - alarm * Function The alarm API requests the kernel to send the SIGALRM signal after a certain number of real clock seconds. * Include: * Summary: unsigned int kill ( unsigned int time_interval); * Return: Success: the number of CPU seconds left in the process timer; Failure: -1; Sets errno: Yes * Argument time_interval: the number of CPU seconds elapsed time, after which the kernel will send the SIGALRM signal to the calling process.