CSC Advanced Unix Programming, Fall 2015

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

2.3 InterProcess Communication (IPC) Part A. IPC methods 1. Signals 2. Mutex (MUTual EXclusion) 3. Semaphores 4. Shared memory 5. Memory mapped files.
1 Select and poll and Signals CS 241 April 6, 2012 University of Illinois.
Page 1 Task Control: Signals and Alarms Havilland and Salama’s Unix Systems Programming B. Ramamurthy.
1 Signals. 2 Communicating with the OS System call (last lecture)  Request to the operating system to perform a task  … that the process does not have.
CPSC 451 Editors and Systems Calls1 Minix editors Mined - (mined) is a simple screen editor. Elle - (elle) is a clone of Emacs. Elvis - (elvis, ex, vi)
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
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.
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.
Section A (March 14) Outline Exceptions Process Signals Non-local jumps Reminders Lab4: Due Next Thursday TA: Kun Gao Shamelessly Modified from Minglong.
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
COMP5102 Lecture 4 Operating Systems (OS) Inter-process Communication phones off (please)
Process states inWindows 2000 and Linux Module 2.1.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Signals & Timers CS241 Discussion Section Spring 2009 Week 6.
Operating Systems Yasir Kiani. 22-Sep Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread.
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
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.
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 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.
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.
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.
© 숙대 창병모 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.
Chapter 8 Signals Source: Robbins and Robbins, UNIX Systems Programming, Prentice Hall, 2003.
Today’s topics Signals and how to control the program behavior in handling signals. Terminal I/O.
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, Abdelzaher1 Signals.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Signals.
Operating Systems Practical Session 3, Signals 1.
Operating Systems Summer Semester 2011 Practical Session 2, 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
Practical Session 3, Signals
UNIT-IV Process and Signals
Chapter 4: Threads.
Signals.
Operating Systems Lecture 12.
Signals Tanzir Ahmed CSCE 313 Fall 2018.
Exceptional Control Flow
Inter-Process Communication ENCE 360
Task Control: Signals and Alarms Chapter 7 and 8
CSE 451: Operating Systems Spring 2006 Module 4 Processes
Signals Jennifer Rexford.
Signals.
Presentation transcript:

CSC 552 - Advanced Unix Programming, Fall 2015 September 30 signals

sigaction() and signal() and kill() A UNIX signal is like a user-process-level interrupt. Each distinct signal provides a way to trigger asynchronous processing in a single-threaded (or multi-threaded) process. sigaction() system call specifies a handler signal() was the old way of doing that kill() system call sends a signal to another process

sigaction() #include <signal.h> int sigaction(int sig, const struct sigaction *restrict act, struct sigaction *restrict oact); The sigaction() function allows the calling process to examine or specify the action to be taken on delivery of a specific signal. See signal.h(3HEAD) for an explanation of general signal concepts. The sigaction structure includes the following members: void (*sa_handler)(int); // SIG_DFL, SIG_IGN or event-handling function void (*sa_sigaction)(int, siginfo_t *, void *); // realtime handler sigset_t sa_mask; // other signals to be blocked during execution int sa_flags; //flags and options

signal.h Signals / default actions are on p. 257 of text SIGHUP 1 Exit Hangup (see termio(7I)) SIGINT 2 Exit Interrupt (see termio(7I)) SIGQUIT 3 Core Quit (see termio(7I)) SIGILL 4 Core Illegal Instruction SIGTRAP 5 Core Trace or Breakpoint Trap SIGABRT 6 Core Abort SIGEMT 7 Core Emulation Trap SIGFPE 8 Core Arithmetic Exception SIGKILL 9 Exit Killed SIGBUS 10 Core Bus Error SIGSEGV 11 Core Segmentation Fault SIGSYS 12 Core Bad System Call SIGPIPE 13 Exit Broken Pipe SIGALRM 14 Exit Alarm Clock SIGTERM 15 Exit Terminated SIGUSR1 16 Exit User Signal 1 SIGUSR2 17 Exit User Signal 2 SIGCHLD 18 Ignore Child Status Changed SIGPWR 19 Ignore Power Fail or Restart SIGWINCH 20 Ignore Window Size Change SIGURG 21 Ignore Urgent Socket Condition SIGPOLL 22 Exit Pollable Event (see streamio(7I)) SIGSTOP 23 Stop Stopped (signal) SIGTSTP 24 Stop Stopped (user) (see termio(7I)) SIGCONT 25 Ignore Continued SIGTTIN 26 Stop Stopped (tty input) (see termio(7I)) SIGTTOU 27 Stop Stopped (tty output) (see termio(7I)) SIGVTALRM 28 Exit Virtual Timer Expired SIGPROF 29 Exit Profiling Timer Expired SIGXCPU 30 Core CPU time limit exceeded (see getrlimit(2)) SIGXFSZ 31 Core File size limit exceeded (see getrlimit(2)) Some abort the process, some core dump by default. See instead man –s7 signal on Linux (above is Solaris).

kill() kill() send a signal to a process #include <sys/types.h> #include <signal.h> int kill(pid_t pid, int sig); pid from getpid(), getppid(), fork() You could pass them via pipes or FIFOs. kill also available as level 1 shell /usr/bin/kill unsigned alarm(unsigned secs) schedules SIGALRM

signal masks signal masks disable target signals until a masked signal is re-enabled unlike SIG_IGN, the ignore+discard handler sigset_t objects can be set up for signals, similar to setting up fd_sets for select()/poll() int sigprocmask(…) sets up signal masks at the process level pthread_sigmask for multi-threaded processes

pause() int pause(void) pauses until interruption by a signal always returns -1 pause() suffers from a race condition – between a call to sigprocmask() and pause(), the signal may already have arrived and been handled signal unmasking and pausing should be atomic

sigsuspend and sigwait int sigsuspend(const sigset_t *set); set is set of masked (disabled) signals former set is restored on return after a non-terminating signal int sigwait(const sigset_t *set, int *sig); synchronously wait on a set of signals in the set this set is independent of the process mask (and thread masks) disable those signals in the process (and thread) masks via sigprocmask() in order to avoid “competition”

race conditions Most 3C library functions and many system calls are not safe to use in a signal handler because its asynchronous execution may occur within a critical section! Text p. 285 holds a list of safe POSIX functions. Perform minimal flag setting within signal handlers. Do not block indefinitely! Do not use sigsetjmp, siglongjmp, setjmp, longjmp – they leak storage from the stack!

Asynchronous I/O and signals aio_read() and aio_write() use signals to generate events on I/O completion. Doing substantial data processing inside a signal handler is extremely error prone! Create a worker thread that is allowed to block, and let it blocks using select(), read() and write(). It can use semaphores, etc. to sync with other threads. Signal handlers cannot!