Task Control: Signals and Alarms Chapter 7 and 8

Slides:



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

Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
6/9/2015B.Ramamurthy1 Process Description and Control B.Ramamurthy.
Process Description and Control
The Process Model.
Page 1 Task Control: Signals and Alarms Havilland and Salama’s Unix Systems Programming B. Ramamurthy.
Unix Processes.
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
Page 1 Processes and Threads Chapter 2. Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
Signals Hua LiSystems ProgrammingCS2690Signals. Topics: Sending Signals -- kill(), raise() Signal Handling -- signal() sig_talk.c -- complete example.
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
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
Process Description and Control A process is sometimes called a task, it is a program in execution.
COMP5102 Lecture 4 Operating Systems (OS) Inter-process Communication phones off (please)
Process states inWindows 2000 and Linux Module 2.1.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
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.
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,
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
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.
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.
Signals (Chap 10 in the book “Advanced Programming in the UNIX Environment”) Acknowledgement : Prof. Y. Moon at Kangwon Nat’l Univ.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.
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 제 10 장 신호 (Signal). © 숙대 창병모 2 Contents 1. Signal Concepts 2. signal() 3. Interrupted System Calls 4. kill() /raise() 5. alarm() pause() 6.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
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)
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, Abdelzaher, Caccamo1 Signals.
UNIX signals.
Processes and threads.
Chapter 3: Process Concept
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Processes.
Threads and Cooperation
Applied Operating System Concepts
CGS 3763 Operating Systems Concepts Spring 2013
CSC Advanced Unix Programming, Fall 2015
Process Description and Control
Process Description and Control
Signals Tanzir Ahmed CSCE 313 Fall 2018.
Process Description and Control
Inter-Process Communication ENCE 360
Task Control: Signals and Alarms Chapter 7 and 8
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Controlling Processes
Chapter 3: Processes.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CSE 451: Operating Systems Spring 2006 Module 4 Processes
Process Management and System Monitoring
Process Description and Control
Signals.
Chapter 3: Process Management
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy 6/24/2018

Multi-tasking How to create multiple tasks? Ex: Xinu create() How to control them? ready() resched() How to synchronize them? How to communicate among them? XINU: semaphores, send and receive messages How to (software) interrupt a process? signals 6/24/2018

Examples Consider g++ myProg.c You want to kill this process after you started the compilation..hit cntrl-C Consider execution of a program called “badprog” >badprog It core dumps .. What happened? The error in the program results in a signal to kernel to stop and dump the offending code Consider “kill –p <pid>” Kill issues a termination signal to the process identified by the pid 6/24/2018

Linux Processes Similar to XINU Procs. Lets understand how to create a linux process and control it. Chapter 7 and 8 of text book. Chapter 7 : multi-tasking Chapter 8: Task communication and synchronization 6/24/2018

Termination of a process Normal completion, time limit exceeded, memory unavailable Bounds violation, protection error, arithmetic error, invalid instruction IO failure, Operator intervention, parent termination, parent request, killed by another process A number of other conditions are possible. Segmentation fault : usually happens when you try write/read into/from a non-existent array/structure/object component. Or access a pointer to a dynamic data before creating it. (new etc.) Bus error: Related to function call and return. You have messed up the stack where the return address or parameters are stored. 6/24/2018

Process Termination Process executes last statement and asks the operating system to delete it (exit) Output data from child to parent (via wait) Process’ resources are deallocated by operating system Parent may terminate execution of children processes (abort) Child has exceeded allocated resources Task assigned to child is no longer required If parent is exiting Some operating system do not allow child to continue if its parent terminates All children terminated - cascading termination 6/24/2018

Signals Signals provide a simple method for transmitting software interrupts to UNIX process Signals cannot carry information directly, which limits their usefulness as an general inter-process communication mechanism However each type of signal is given a mnemonic name; Ex: SIGINT See signal.h for others SIGHUP, SIGINT, SIGILL, SIGTRAP, SIGFPE, SIGKILL SIGALRM (sent by kernel to a process after an alarm timer has expired) SIGTERM signal (signal id, function) simply arms the signal 6/24/2018

Signal Value Action Comment ------------------------------------------------------------------------- SIGHUP 1 Term Hangup detected on controlling terminal or death of controlling process SIGINT 2 Term Interrupt from keyboard SIGQUI 3 Core Quit from keyboard SIGILL 4 Core Illegal Instruction SIGABR 6 Core Abort signal from abort(3) SIGFP 8 Core Floating point exception SIGKILL 9 Term Kill signal SIGSEG 11 Core Invalid memory reference SIGPIPE 13 Term Broken pipe: write to pipe with no readers SIGALRM 14 Term Timer signal from alarm(2) SIGTERM 15 Term Termination signal SIGUSR1 30,10,16 Term User-defined signal 1 SIGUSR2 31,12,17 Term User-defined signal 2 SIGCHLD 20,17,18 Ign Child stopped or terminated SIGCONT 19,18,25 Cont Continue if stopped SIGSTOP 17,19,23 Stop Stop process SIGTSTP 18,20,24 Stop Stop typed at tty SIGTTIN 21,21,26 Stop tty input for background process SIGTTOU 22,22,27 Stop tty output for background process The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored. 6/24/2018

Realtime signals Linux supports real-time signals as originally defined in the POSIX.1b real-time extensions (and now included in POSIX.1-2001). Linux supports 32 real-time signals, numbered from 32 (SIGRTMIN) to 63 (SIGRT- MAX) Main difference is that these are queued and not lost. Realtime signals are delivered in guaranteed order. 6/24/2018

Intercept Signals Task1 Task2 Two essential parameters are destination process identifier and the signal code number: kill (pid, signal) Signals are a useful way of handling intermittent data arrivals or rare error conditions. 6/24/2018

Handling Signals Look at the examples: Catching SIGALRM Ignoring SIGALRM sigtest.c sigHandler.c pingpong.c See /usr/include/sys/iso/signal_iso.h for signal numbers 6/24/2018

Signals and Alarms #include <signal.h> unsigned int alarm( unsigned int seconds ); alarm(a); will start a timer for a secsonds and will interrupt the calling process after a secs. time(&t); will get you current time in the variable t declared as time_t t ctime(&t); will convert time to ascii format Alarm has a sigaction function that is set for configuring the alarm handler etc. sigaction(SIGALRM, &act, &oldact) ; the third paramter is for old action configuration 6/24/2018

Sample programs Starting new tasks in linux: page 165 Programs in pages: 174-180 on signals and alarms See demos directory for the code See page 175 for the second program See page 178 … for the third program 6/24/2018

Pingpong Parent PSIG 43 Child CSIG 42 6/24/2018

Observe in pingpong.c pause(): indefinite sleep(): sleep is random/finite time While loop Signal handlers Re-arming of the signals 6/24/2018

Input/output Resources What is standard IO? These are resources allocated to the process at the time of creation: From Wikipedia/Standard_streams 6/24/2018

Volatile A variable should be declared volatile whenever its value could change unexpectedly. In practice, only three types of variables could change: Memory-mapped peripheral registers Global variables modified by an interrupt service routine Global variables within a multi-threaded application Registers in devices are abstracted for programmatic access as “volatile” type 6/24/2018

Summary We studied signals and alarms and their specification and example programs 6/24/2018