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.

Slides:



Advertisements
Similar presentations
Operating System Structures
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
1 Exceptions, Interrupts & Traps Operating System Hebrew University Spring 2007.
Input and Output CS 215 Lecture #20.
Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 3 – Process Concepts Outline 3.1 Introduction 3.1.1Definition of Process 3.2Process States:
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
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.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
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.
Section A (March 14) Outline Exceptions Process Signals Non-local jumps Reminders Lab4: Due Next Thursday TA: Kun Gao Shamelessly Modified from Minglong.
Exceptions, Interrupts & Traps
1 Signals and Session Management Chapter 4. 2 Contents u Signal Generation and Handling u Unreliable Signals u Reliable Signals u Signals in SVR4 u Signals.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems CSE 411 CPU Management Sept Lecture 9 Instructor: Bhuvan Urgaonkar.
CSC 2405 Computer Systems II Exceptions Mini-Lecture Traps & Interrupts.
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
Washington WASHINGTON UNIVERSITY IN ST LOUIS Core Inter-Process Communication Mechanisms (Historically Important) Fred Kuhns
Exceptional Control Flow Topics Exceptions except1.ppt CS 105 “Tour of the Black Holes of Computing”
Process Models, Creation and Termination Reference –text: Tanenbaum ch. 2.1.
Outline for Today Objectives –Finish discussion of Birrell –UNIX Signals –Eraser Administrative –Spider talk after class.
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
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.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Signals & Message queue Inter process mechanism in Linux system 3/24/
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
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.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Process Relationships Chien-Chung Shen CIS/UD
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
Exceptional Control Flow
Exceptional Control Flow
Chapter 3 – Process Concepts
Unix Process Management
Threads CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Structure of Processes
Process Models, Creation and Termination
Exceptions Control Flow
Exceptional Control Flow
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes Creation and Threads
Process Description and Control in Unix
Process Description and Control in Unix
Chapter 4: Threads.
Presentation transcript:

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 management

2 What is signal n signal is a mechanism of primitive communication, synchronization and notification n two phases: u generation - when event occurs that requires the process to be notified of it u delivery (handling) - the process recognized the arrival of event and takes appropriate action F asynchronous - example: user sends an interrupt signal by pressing ctrl-C F synchronous - example: accessing illegal address n between generation and delivery - signal is pending n Type is associated with signal. It is an integer. It is different on different Unix flavors. Usually symbolic constants rather than integers are used to denote signals. Example: SIGHUP

3 Signal handling n A program can specify how to handle a certain signal by specifying (installing) signal handler - a function that is called when signal is delivered n default actions - if no specification is given: u abort - process terminates after dumping core u exit - process terminates, no coredump u ignore - ignores signal u stop - suspends process u continue - resumes process if suspended, otherwise - ignore n the signal delivery (and default handling) is done by kernel u when there is a signal to be delivered - the kernel checks if process specified a handler for this type of signal F if yes - calls handler F if not - takes one of the default actions n note that the process needs to be running to receive signals n kernel delivers signals on the following three occasions: u before returning to user mode from a system call or interrupt u just before blocking on interruptible event u immediately after waking up from interruptible event

4 User program signal handling n A program may elect to let the kernel handle the signal, install it’s own signal handler or have it blocked (ignored) n installing SIGINT handler void sigint_handler (int sig){ … /* handles signal */ } main(){ /* installs handler */ signal (SIGINT, sigint_handler); … } n handler is executed “out of sequence” n before switch to user mode kernel transfers control to signal handler n and makes arrangements to return to previous point of execution n how can we do this? normal code executes signal delivered signal handler runs resume normal execution

5 Signal generation n Kernel generates signals to a process on various events. n Some classes of events: u exceptions - attempt to execute illegal instruction, access memory out of range, division by zero, etc. u other processes - may send signals u terminal interrupts - certain keyboard characters generate signals (Ctrl-C) u notification - a process may request to be notified of certain event like device being ready for I/O

6 Signal example usage n Asynchronous: u a user presses ctrl-C which generates keyboard interrupt u the interrupt is handled by terminal driver which generates SIGINT for the “foreground” process u when this process is scheduled to run, before it switches to user mode the kernel checks if the process installed signal handler F if yes - kernel makes the signal handler the first function to run in the user mode F if no - the kernel terminates the process n Synchronous: u division by zero occurs - trap switches to kernel mode u trap handler recognizes the exception and either sends the signal to installed signal handler or aborts the process

7 Terminal management n process group u each process has a process group identified by process group ID u process group is different from user group u each group has a leader; group ID is process ID of the leader. Leader - process whose group ID is its process ID u when process is created it inherits group from parent u can leave group by executing a system call and becoming a new group leader n controlling terminal u process may have controlling terminal - usually the terminal at which process was created u all processes of the same group share controlling terminal u process accepts input and sends output to controlling terminal n /dev/tty u a special file which is the controlling terminal for each process u the terminal driver routes the requests to appropriate terminal n controlling group - receives keyboard-generated signals (SIGINT...)

8 Terminal management (cont.) n When login shell execs a program at users request this process inherits a the shell’s group ID n this a user process usually u belongs to a controlling group of the terminal it was launched from - receives keyboard generated signals u has this terminal as its controlling terminal - receives keyboard input, outputs to terminal n if a process executes the command to reset its process group it loses the controlling terminal and leaves controlling group becoming a daemon process