B. RAMAMURTHY Pag e 1 Task Control: Signals and Alarms Chapter 7 and 8 7/2/2015.

Slides:



Advertisements
Similar presentations
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Advertisements

Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Introduction to Processes
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.
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.
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
Process Description and Control A process is sometimes called a task, it is a program in execution.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
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)
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
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.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
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)
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
UNIX signals.
Task Control: Signals and Alarms Chapter 7 and 8
Unix Process Management
Chapter 3: Processes.
System Structure and Process Model
System Structure and Process Model
Structure of Processes
CGS 3763 Operating Systems Concepts Spring 2013
System Structure B. Ramamurthy.
CSC Advanced Unix Programming, Fall 2015
System Structure and Process Model
Operating Systems Lecture 6.
Process & its States Lecture 5.
Process Description and Control
Process Description and Control
Process Description and Control
Inter-Process Communication ENCE 360
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
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
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Process Description and Control
Process Description and Control
Process Description and Control in Unix
Signals.
Process Description and Control in Unix
Chapter 3: Process Management
Presentation transcript:

B. RAMAMURTHY Pag e 1 Task Control: Signals and Alarms Chapter 7 and 8 7/2/2015

Multi-tasking Pag e 2 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 7/2/2015

Examples Pag e 3 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 ”  Kill issues a termination signal to the process identified by the pid 7/2/2015

Linux Processes Pag e 4 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 7/2/2015

Process creation Pag e 5 Four common events that lead to a process creation are: 1) When a new batch-job is presented for execution. 2) When an interactive user logs in / system initialization. 3) When OS needs to perform an operation (usually IO) on behalf of a user process, concurrently with that process. 4) To exploit parallelism an user process can spawn a number of processes. 7/2/2015

Termination of a process Pag e 6 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. 7/2/2015

Process control Pag e 7 Process creation in unix is by means of the system call fork(). OS in response to a fork() call:  Allocate slot in the process table for new process.  Assigns unique pid to the new process..  Makes a copy of the process image, except for the shared memory.  both child and parent are executing the same code following fork()  Move child process to Ready queue.  it returns pid of the child to the parent, and a zero value to the child. 7/2/2015

Process control (contd.) Pag e 8 All the above are done in the kernel mode in the process context. When the kernel completes these it does one of the following as a part of the dispatcher:  Stay in the parent process. Control returns to the user mode at the point of the fork call of the parent.  Transfer control to the child process. The child process begins executing at the same point in the code as the parent, at the return from the fork call.  Transfer control another process leaving both parent and child in the Ready state. 7/2/2015

Page 9 Process Creation (contd.) Parent process create children processes, which, in turn create other processes, forming a tree of processes Generally, process identified and managed via a process identifier (pid) Resource sharing  Parent and children share all resources  Children share subset of parent’s resources  Parent and child share no resources Execution  Parent and children execute concurrently  Parent waits until children terminate 7/2/2015

Page 10 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 7/2/2015

Example Code 1. int retVal; 2. printf(" Just one process so far\n"); 3. printf(" Invoking/Calling fork() system call\n"); 4. retVal = fork(); /* create new process*/ 5. if (retVal == 0) 6. printf(" I am the child %d \n",getpid()); 7. else if (retVal > 0) 8. printf(" I am the parent, child has pid %d \n", retVal); 9. else 10. printf(" Fork returned an error %d \n", retVal); 7/2/2015 Pag e 11

Input/output Resources What is standard IO? These are resources allocated to the process at the time of creation: From Wikipedia/Standard_streams 7/2/2015 Pag e 12

Signals Pag e 13 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 7/2/2015

Page 14 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.

Realtime signals Linux supports real-time signals as originally defined in the POSIX.1b real-time extensions (and now included in POSIX ). 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. 7/2/2015 Pag e 15

Intercept Signals Pag e 16 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. 7/2/2015

Handling Signals Pag e 17 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 7/2/2015

Signals and Alarms Pag e 18 #include 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 7/2/2015

Sample programs Pag e 19 Starting new tasks in linux: page 165 Programs in pages: on signals and alarms See demos directory for the code See page 175 for the second program See page 178 … for the third program 7/2/2015

Pingpong Pag e 20 Parent Child PSIG 43 CSIG 42 7/2/2015

Observe in pingpong.c pause(): indefinite sleep(): sleep is random/finite time While loop Signal handlers Re-arming of the signals 7/2/2015 Pag e 21

Volatile Pag e 22 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 7/2/2015

Summary 7/2/2015 Pag e 23 We studied signals and alarms and their specification and example programs