Shell Execution of Programs. Process Groups, Session and Signals 1

Similar documents
Unix System Programming - Chapter 8

CS631 - Advanced Programming in the UNIX Environment. Process Groups, Sessions, Signals

Advanced Unix/Linux System Program. Instructor: William W.Y. Hsu

Signals. Joseph Cordina

Overview. Administrative. * HW 1 grades. * HW 2 Due. Topics. * 5.1 What is a Signal? * Dealing with Signals - masks, handlers

Signals. POSIX defines a variety of signal types, each for a particular

Process. Signal #8. Signals are software interrupts from unexpected events. a power failure. an alarm clock. the death of a child process

CSE 421: Introduction to Operating Systems

Lesson 3. The func procedure allows a user to choose the action upon receipt of a signal.

Operating Systems 2010/2011

CSci 4061 Introduction to Operating Systems. (Advanced Control Signals)

Lecture 7: Signals and Events. CSC 469H1F Fall 2006 Angela Demke Brown

KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 6

ECE 650 Systems Programming & Engineering. Spring 2018

Signals: Management and Implementation. Sanjiv K. Bhatia Univ. of Missouri St. Louis

Signals and Session Management. Signals. Mechanism to notify processes of system events

Multitasking. Programmer s model of multitasking. fork() spawns new process. exit() terminates own process

Chapter 8: I/O functions & socket options

Signals, Synchronization. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

System Programming. Signals I

Chapter 4 Multithreaded Programming

Signals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Programming Assignments will be.. All the PAs are continuous 3 major factors that you should consider

A read or write being atomic means that its effect is as if it happens instantaneously.

Preview. Process Termination. wait and waitpid() System Call. wait and waitpid() System Call. waitpid() System Call 10/23/2018

Embedded Systems Programming

Operating Systems. Threads and Signals. Amir Ghavam Winter Winter Amir Ghavam

3.1 Introduction. Computers perform operations concurrently

Introduction. Interprocess communication. Terminology. Shared Memory versus Message Passing

Interprocess Communication

Signals are a kernel-supported mechanism for reporting events to user code and forcing a response to them. There are actually two sorts of such

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

COSC243 Part 2: Operating Systems

Acontecimentos assíncronos (POSIX signals) Sincronização com múltiplos acontecimentos

Other Interprocess communication (Chapter 2.3.8, Tanenbaum)

Preview. The pause() System Call. The pause() System Call. The signal() System Call 10/18/2017

Each terminal window has a process group associated with it this defines the current foreground process group. Keyboard-generated signals are sent to

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

Most of the work is done in the context of the process rather than handled separately by the kernel

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 19

UNIT III - APPLICATION DEVELOPMENT. TCP Echo Server

Lecture 9: Real-Time Software Design Issues

Project 2: Signals. Consult the submit server for deadline date and time

Concurrent Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

SMD149 - Operating Systems

n Unconditionally kill process 8371 n Interactive interrupt key n See /usr/include/bits/signum.h (e.g., SIGKILL 9) 2 -Ken Wong, Sep 2008

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

UNIX System Programming. Overview. 2. Signal Types (31 in POSIX) Signal Sources. Signals. 1. Definition

Workshop on Inter Process Communication Solutions

Processes & Signals. System Runs Many Processes Concurrently. State consists of memory image + register values + program counter

Interprocess Communication Mechanisms

shared storage These mechanisms have already been covered. examples: shared virtual memory message based signals

Processes. Dr. Yingwu Zhu

系統程式 郭大維教授 / 施吉昇教授臺灣大學資訊工程系

Memory-Mapped Files. generic interface: vaddr mmap(file descriptor,fileoffset,length) munmap(vaddr,length)

Linux Signals and Daemons

Signals. CSC209: Software Tools and Systems Programming. Furkan Alaca & Paul Vrbik

* What are the different states for a task in an OS?

CSE410 Operating Systems Spring 2018 Project 1: Introduction to Unix/Linux Signals

Deviations are things that modify a thread s normal flow of control. Unix has long had signals, and these must be dealt with in multithreaded

Design Overview of the FreeBSD Kernel CIS 657

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

System Calls & Signals. CS449 Spring 2016

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

Killing Zombies, Working, Sleeping, and Spawning Children

Advanced Programming in the UNIX Environment W. Richard Stevens

ESE 333 Real-Time Operating Systems 2 What is an operating system? Two views: 1. Top-down view: Extended machine ffl Covers the details of the hardwar

CS213. Exceptional Control Flow Part II. Topics Process Hierarchy Signals

Processes. Sanzheng Qiao. December, Department of Computing and Software

CS240: Programming in C

CSCI 4061: Signals and Signal Handlers

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Exceptions, Processes and Signals

Shell and Signals. Computer Organization 3/17/2015. CSC252 - Spring The World of Multiprogramming or Multitasking. Unix Process Hierarchy

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534

CSE 120 Principles of Operating Systems

Overview. POSIX signals. Generation of signals. Handling signals. Some predefined signals. Real-time Systems D0003E 3/3/2009

Chapter 5. TCP Client-Server

IMPLEMENTATION OF SIGNAL HANDLING. CS124 Operating Systems Fall , Lecture 15

PROCESS CONCEPTS. Process Concept Relationship to a Program What is a Process? Process Lifecycle Process Management Inter-Process Communication 2.

System Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch

PVPSIDDHARTHA INSTITUTE OF TECHNOLOGY

Concurrency Problems Signals & Synchronization Semaphore Mutual Exclusion Critical Section Monitors

Chapter 9. Signals and Signal Processing

Signals. Goals of this Lecture. Help you learn about: Sending signals Handling signals

Interprocess Communication Mechanisms

Interprocess Communication Mechanisms

Operating Systems 9/6/ SIGINT Terminate Interrupt from keyboard (ctl-c) 9 SIGKILL Terminate Kill program (cannot override or ignore)

Implementing Lightweight Threads

Process Control. Philipp Koehn. 23 April 2018

CSE 120 Principles of Operating Systems

Programs. Program: Set of commands stored in a file Stored on disk Starting a program creates a process static Process: Program loaded in RAM dynamic

Last time: Scheduling. Goals today. Recap: Hardware support for synchronization. Disabling interrupts. Disabling interrupts

Exceptions, Interrupts, and Timers

CSC209 Review. Yeah! We made it!

CSC209H Lecture 8. Dan Zingaro. March 4, 2015

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Overview. Administrative. * HW 2 Grades. * HW 3 Due. Topics: * What are Threads? * Motivating Example : Async. Read() * POSIX Threads

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

Course Syllabus. Operating Systems, Spring 2016, Meni Adler, Danny Hendler & Amnon Meisels

Transcription:

Shell Execution of Programs Process Groups, Session and Signals 1

Signal Concepts Signals are a way for a process to be notified of asynchronous events (software interrupts). Some examples: a timer you set has gone off (SIGALRM) some I/O you requested has occurred (SIGIO) a user resized the terminal window (SIGWINCH) a user disconnected from the system (SIGHUP)... The process can t simply test a variable (such as errno) to see whether a signal has occurred; instead, the process has to tell the kernel if and when this signal occurs, do the following. ). See also: signal(2)/signal(3)/signal(7) (note: these man pages vary significantly across platforms!) Process Groups, Session and Signals 2

Signal Concepts Besides the asynchronous events listed previously, there are many ways to generate a signal: terminal generated signals (user presses a key combination which causes the terminal driver to generate a signal) hardware exceptions (divide by 0, invalid memory references, etc) kill(1) allows a user to send any signal to any process (if the user is the owner or superuser) kill(2) (a system call, not the Unix command) performs the same task software conditions (other side of a pipe no longer exists, urgent data has arrived on a network file descriptor, etc.) Process Groups, Session and Signals 3

Signals Process Groups, Session and Signals 4

Signals Process Groups, Session and Signals 5

Signal Concepts Once we get a signal, we can do one of several things: Ignore it. (note: there are some signals which we CANNOT or SHOULD NOT ignore) Catch it. That is, have the kernel call a function which we define whenever the signal occurs. Accept the default. Have the kernel do whatever is defined as the default action for this signal Process Groups, Session and Signals 6

signal(3) Establish a signal handler. func can be: SIG IGN which requests that we ignore the signal signo SIG DFL which requests that we accept the default action for signal signo or the address of a function which should catch or handle a signal Process Groups, Session and Signals 7

Signal Examples Process Groups, Session and Signals 8

Signal Examples Process Groups, Session and Signals 9

Program Startup When a program is executed, the status of all signals is either default or ignore. When a process fork(2)s, the child inherits the parent s signal dispositions. A limitation of the signal(3) function is that we can only determine the current disposition of a signal by changing the disposition. Process Groups, Session and Signals 10

Interrupted System Calls Some system calls can block for long periods of time (or forever). These include things like: read(2)s from files that can block (pipes, networks, terminals) write(2) to the same sort of files open(2) of a device that waits until a condition occurs (for example, a modem) pause(3), which purposefully puts a process to sleep until a signal occurs certain ioctl(3)s certain IPC functions Process Groups, Session and Signals 11

Interrupted System Calls Catching a signal during execution of one of these calls traditionally led to the process being aborted with an errno return of EINTR. This was done under the assumption that since a signal occurred and the process caught it, there is a good chance that something has happened that should wake up the blocked system call. Process Groups, Session and Signals 12

Interrupted System Calls Previously necessary code to handle EINTR: Nowadays, many Unix implementations automatically restart certain system calls. Process Groups, Session and Signals 13

Non-reentrant functions in signal hander Process Groups, Session and Signals 14

Non-reentrant functions in signal hander When this program was run, the results were random. The main function had called getpwnam, but that when getpwnam called free, the signal handler interrupted it and called getpwnam, which in turn called free. The data structures maintained by malloc and free had been corrupted when the signal handler (indirectly) called free while the main function was also calling free. Occasionally, the program would run for several seconds before crashing with a SIGSEGV error. Process Groups, Session and Signals 15

Reentrant Functions Process Groups, Session and Signals 16

kill(2) and raise(3) The kill function sends a signal to a process or a group of processes. pid > 0 signal is sent to the process whose PID is pid pid == 0 signal is sent to all processes whose process group ID equals the process group ID of the sender pid == -1 POSIX.1 leaves this undefined, BSD defines it (see kill(2)) The raise function allows a process to send a signal to itself. Process Groups, Session and Signals 17

alarm(2) and pause(2) The alarm function allows us to set a timer that will expire at a specified time in the future. When the timer expires, the SIGALRM signal is generated. If we ignore or don t catch this signal, its default action is to terminate the process. The pause function suspends the calling process until a signal is caught. Process Groups, Session and Signals 18

Signal Sets More advanced signal handling can be done via signal sets representing multiple signals Process Groups, Session and Signals 19

sigprocmask(2) The signal mask of a process is the set of signals currently blocked from delivery to that process. A process can examine its signal mask, change its signal mask, or perform both operations in one step by calling the sigprocmask() function. Process Groups, Session and Signals 20

sigpending(2) The sigpending function returns the set of signals that are blocked from delivery and currently pending for the calling process. Process Groups, Session and Signals 21

Process Groups, Session and Signals 22

Process Groups, Session and Signals 23

Process Groups, Session and Signals 24

sigaction(2) This function allows us to examine or modify the action associated with a particular signal. signal(3) is (nowadays) commonly implemented via sigaction(2). Process Groups, Session and Signals 25

An implementation of signal using sigaction Process Groups, Session and Signals 26

sigsuspend(2) The signal mask of the process is set to the value pointed to by sigmask. Then the process is suspended until a signal is caught or until a signal occurs that terminates the process. Two operations are executed in a single atomic operation.. Provides a correct way to protect a critical region of code from a specific signal. Process Groups, Session and Signals 27

Protecting a critical region from a signal Process Groups, Session and Signals 28

Protecting a critical region from a signal Process Groups, Session and Signals 29

Protecting a critical region from a signal Process Groups, Session and Signals 30

Parent-child synchronization with signal Process Groups, Session and Signals 31

Parent-child synchronization with signal Process Groups, Session and Signals 32

Parent-child synchronization with signal Process Groups, Session and Signals 33

abort(3) This function sends the SIGABRT signal to the caller. (Processes should not ignore this signal.) The intent of letting the process catch the SIGABRT is to allow it to perform any cleanup that it wants to do before the process terminates. Process Groups, Session and Signals 34

system() function handling signals Process Groups, Session and Signals 35

system() function handling signals Process Groups, Session and Signals 36

system() function handling signals Process Groups, Session and Signals 37

Correct implementation of system function Process Groups, Session and Signals 38

Process Groups, Session and Signals 39

sleep(3) This function causes the calling process to be suspended until either The amount of wall clock time specified by seconds has elapsed. A signal is caught by the process and the signal handler returns. Process Groups, Session and Signals 40

Signal Queuing Most UNIX systems don t queue signals. But some systems do. Signals arriving while a handler runs are queued unless they are blocked. Multiple identical signals are queued, but you can receive a different signal while in a signal handler. Process Groups, Session and Signals 41

Questions? Process Groups, Session and Signals 42