Signals Notifies a process of an event

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)
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.
15-213, Fall 06 Outline Shell Lab Processes Signals.
System Programming Project 2 Due : 4/19...?. Foreground & Background Foreground job Foreground job Only one at moment Only one at moment Having user’s.
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.
SignalsSignals. What is a Signal? A signal is a notification that some event has occurred. Usually a signal is sent to a process asynchronously and whatever.
Signals Notifies a process of an event Generated when event that causes signal occurs Delivered when the process takes action based on the signal A signal.
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)
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
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.
Project 1. Process ID (pid) Synopsis #include pid_t getpid(void) – returns the pid of the currently running process. pid_t getppid(void) – returns the.
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.
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)
Carnegie Mellon 1 Processes, Signals, I/O, Shell Lab : Introduction to Computer Systems Recitation 9: 10/21/2013 Tommy Klein Section B.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Signals & Timers CS241 Discussion Section Spring 2009 Week 6.
1Reference “Introduction To Unix Signals Programming” in the reference material section Man page – sigprocmask, alarm “Understanding the Linux Kernel”
CS 497C – Introduction to UNIX Lecture 6: General-Purpose Utilities Chin-Chih Chang
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands Major part of the of learning.
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.
Signals and Signal Processing CIS 370 Lab 7 Umass Dartmouth.
Outline for Today Objectives –Finish discussion of Birrell –UNIX Signals –Eraser Administrative –Spider talk after class.
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.
SignalsSignals. What is a Signal? A signal is a notification that some event has occurred. Usually a signal is sent to a process asynchronously and whatever.
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.
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.
KUKUM Real Time System Module #3 POSIX programming Lecture 2.
© 숙대 창병모 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.
Signals & Message queue Inter process mechanism in Linux system 3/24/
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)
CS 241 Section Week #10 (04/01/10) ‏. Topics This Section  MP5 Overview  Signals.
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 Inter-Process Communication Signals Moti Geva
UNIX signals.
G.Jyostna.
Signals What is a Signal?
Task Control: Signals and Alarms Chapter 7 and 8
CS 3733 Operating Systems Topics: Signals (USP Chapter )
UNIT-IV Process and Signals
CSC Advanced Unix Programming, Fall 2015
Signals Tanzir Ahmed CSCE 313 Fall 2018.
Inter-Process Communication ENCE 360
Signals.
Presentation transcript:

Signals Notifies a process of an event Generated when event that causes signal occurs Delivered when the process takes action based on the signal A signal is pending if it has been generated but is not yet delivered. The lifetime of a signal is the interval between generation and delivery.

Signal Handling A process catches a signal if it executes a signal handler when the signal is delivered A program installs a signal handler by making a call to the sigaction system call

Signal Handlers The sigaction system call installs either: A user defined function SIG_DFL – a default routine SIG_IGN – ignore the signal

Masking Signals The action taken on receipt of a signal depends on the current signal handler for that signal and the signal mask for the process The mask identifies the currently blocked signals You change a signal mask with the sigprocmask system call blocking is different from ignoring – you ignore a signal by installing SIG_IGN with sigaction

POSIX Required Signals Symbol Meaning SIGABRT SIGBUS SIGALRM SIGFPE SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV SITTERM SIGURG SIGUSR1 SIGUSR2 Abnormal termination as initiated by abort Access undefined part of memory object Timeout signal as initiated by alarm Error in arithmetic operation as in division by zero Hang up (deat) on controlling terminal (process) Invalid hardware instruction Interactive attention signal Terminate (cannot be caught or ignored) Write on a pipe with no readers Interactive termination Invalid memory reference Termination High bandwidth data available at a socket User-defined signal 1 User-defined signal 2

POSIX Job Control Signals Symbol Meaning SIGCHLD SIGCONT SIGSTOP SIGTSTP SIGTTIN SIGTTOU Indicates child process terminated or stopped Continue if stopped (done when generated) Stop signal (cannot be caught or ignored) Interactive stop signal Background process attempts to read from controlling terminal Background process attempts to write to controlling terminal

Generation of Signals Some signals are generated with errors occur (i.e., SIGFPE or SIGEGV) A user can send signals to a process that it owns (the effective user ID of the sending and receiving processes are the same) Signals can be generated from the shell with a kill system call

kill Command SYNOPSIS kill –s signal_name pid… kill –l [exit status] kill [-signal_name] pid… kill [-signal number] pid… POSIX: Shell and Utilities

Signal_Name Example kill –USR1 3423 or kill –s USR1 3423 Sends SIGUSR1 to process 3423 USR1 is a symbolic name for the signal SIGUSR1

Signal_Number Example kill –9 3423 Sends signal number 9 (SIGKILL) to process 3423 The only supported signal number values are: 0 for signal 0 1 for signal SIGHUP 2 for signal SIGINT 3 for signal SIGQUIT 6 for signal SIGABRT 9 for signal SIGKILL 14 for signal SIGALRM 15 for signal SIGTERM

Signal Symbolic Names Typing kill –l on the ect-unix machines causes the following to be output: EXIT HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM USR1 USR2 CLD PWR WINCH URG POLL STOP TSTP CONT TTIN TTOU VTALRM PROF XCPU XFSZ WAITING LWP FREEZE THAW CANCEL LOST RTMIN RTMIN+1 RTMIN+2 RTMIN+3 RTMAX-3 RTMAX-2 RTMAX-1 RTMAX

kill System Call SYNOPSIS #include <signal.h> int kill(pid_t pid, int sig); POSIX:CX

errno for kill System Call cause EINVAL sig is an invalid or unsupported signal EPERM caller does not have the appropriate privileges ESRCH no process or process group corresponds to pid

kill System Call Example #include <stdio.h> #include <sys/types.h> #inlcude <signal.h> if (kill(3423, SIGUSR1) == -1) perror(“Could not send SIGUSR1”); if (kill (getppid(), SIGTERM) == -1) perror(“Error in kill”);

raise System Call SYNOPSIS #include <signal.h> int raise(int sig); POSIX:CX A process can send a signal to itself with a raise system call – Example: if (raise (SIGUSR1) != 0) perror (“Failed to raise SIGUSR1”);

stty –a Among other things, the stty –a output associates signals with control keystroke inputs

Output of stty –a on ect-unix Machine speed 9600 baud; rows 24; columns 80; intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; dsusp = ^Y; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; -parenb parodd cs8 hupcl cstopb cread -clocal crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon ixoff -iuclc -ixany -imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

Signal Generating Characters The INTR character, ctrl-c, generates SIGINT for the foreground process The QUIT character, ctrl-|, generates SIGQUIT The SUSP character, ctrl-z, generates SIGSTOP The DSUP character, ctrl-y, generates SIGCONT

alarm System Call SYNOPSIS include <unistd.h> unsigned int alarm(unsigned int seconds); Posix.1 Spec 1170 Causes SIGALRM signal to be sent to calling process after the specified number of seconds have elapsed – Example: #include <unistd.h> void main(void) { alarm(10); for( ; ; ) {} }

Signal Mask and Signal Sets A process can temporarily prevent a signal from being delivered by blocking it The process signal mask contains the set of signals that are currently blocked When a process blocks a signal, an occurrence of the signal is held until the signal is unblocked (blocked signals do not get lost – ignored signals do get lost)

Signal Set Functions sigemptyset – remove all signals from the signal set sigfillset – initializes a signal set to contain all signals sigaddset – adds a specified signal to a signal set sigdelset – removes a specified signal from a signal set sigismember – tests to see if a specified signal is in a signal set

sigprocmask System Call SYNOPSIS #include <signal.h> int sigprocmask(int how,const sigset_t *set, sigset_t *oset); Posix.1, Spec 1170

sigprocmask – how parameter SIG_BLOCK – add the collection of signals in the parameter set to those already in the signal set SIG_UNBLOCK – delete the collection of signals in the parameter set from the signal set SIG_SETMASK – replace the entire current signal set with the collection of signals in the parameter set

sigprocmask – Example 1 #include <stdio.h> #include <signal.h> sigset_t newsigset; sigemptyset(&newsigset); /* newsigset is empty */ sigaddset(&newsigset, SIGINT); /* add SIGINT to newsigset */ if (sigprocmask (SIG_BLOCK, &newsigset, NULL) < 0) perror(“Could not block the signal”); The above code causes the signal SIGINT to be blocked.

sigprocmask – Example 2 … sigemptyset (&intmask); sigaddset (&intmask, SIGINT); sigprocmask(SIG_BLOCK, &intmask, NULL); /* if ctrl-c is typed while this code is executing, the SIGINT signal is blocked */ sigprocmask(SIG_UNBLOCK, &intmask, NULL); /* a ctrl-c typed while either this OR THE ABOVE code is excuting is handled here */

sigprocmask – Example 3 … sigfillset(&blockmask); sigprocmask(SIG_SETMASK, &blockmask, &oldset); /* all signals are blocked here */ sigprocmask(SIG_SETMASK, &oldset, NULL); /* the old signal set goes back into effect here */

sigaction System Call SYNOPSIS int sigaction(int signo, const struct sigaction *act, struct sigaction *oact); struct sigaction { void (*sa_handler)(); /* SIG_DFL, SIG_IGN, or pointer to function */ sigset_t sa_mask /* additional signals to be blocked during execution of handler */ int sa_flags /* special flags and options */ The sigaction system call installs signal handlers for a process. The data structure struct sigaction holds the handler information

sigaction – Example 1 Installs mysighand signal handler for SIGINT #include <signal.h> #include <stdio.h> #include <sys/types.h> #include <string.h> char handmsg[] = “I found ^c\n”; void mysighand(int signo) { write (STDERR_FILENO, handmsg, strlen(handmsg)); } … struct sigaction newact; … newact.sa_handler = mysighand; /* set the new handler */ sigemptyset(&newact.sa_mask); /* no other signals blocked */ newact.sa_flags = 0; /* no special options */ if (sigaction(SIGINT, &newact, NULL) == -1) perror("Could not install SIGINT signal handler"); Installs mysighand signal handler for SIGINT

sigaction – Example 2 struct sigaction act; struct sigaction oact; /* Download old signal handler */ if (sigaction(SIGINT, NULL, &oact) == -1) perror("Could not get old handler for SIGINT"); else if (oact.sa_handler == SIG_DFL) { /* ignore SIGINT */ act.sa_handler = SIG_IGN; /* set new handler to ignore */ if (sigaction(SIGINT, &act, NULL) == -1) perror("Could not ignore SIGINT"); else { printf("Now ignoring SIGINT for 10 seconds\n"); sleep(10); if (sigaction(SIGINT, &oact, NULL) == -1) perror("Could not restore old handler for SIGINT"); printf("Old signal handler restored\n"); } } This code downloads the current sigaction structure, checks to see if the current handler is the default handler, and if so, ignores SIGINT for 10 seconds

Set Handler to Default struct sigaction newact; newact.sa_handler = SIG_DFL; /* new handler set to default */ sigemptyset(&newact.sa_mask); /* no other signals blocked */ newact.sa_flags = 0; /* no special options */ if (sigaction(SIGINT, &newact, NULL) == -1) perror("Could not set SIGINT handler to default action");

pause System Call SYNOPSIS #include<unistd.h> int pause (void); POSIX Pause suspends the calling process until a signal that is not being blocked or ignored is delivered to the process. It does not allow resetting of the signal mask.

Pause – Example 1 #include <unistd.h> int signal_received = 0; /* external static variable */ … while(signal_received == 0) pause(); If the signal is delivered in between the test of signal_received and pause, the pause will not return until another signal is delivered to the process.

pause – Example 2 … int signal_received = 0; /* external static variable */ sigset_t sigset; int signum; sigemptyset(&sigset); sigaddset(&sigset, signum); sigprocmask(SIG_BLOCK, &sigset, NULL); While(signal_received == 0) pause(); This does not solve the Example 1 pause problem because pause is executed while signum is blocked.

sigsuspend System Call SYNOPSIS #include <signal.h> int sigsuspend(const sigset_t *sigmask) POSIX:CX Solves the problems encountered with pause by temporarily installing sigmask when sigsuspend is called.

sigsuspend – Example 1 int signum = SIGUSR1; sigfillset (&sigmost); sigdelset(&sigmost, signum); sigsuspend(&sigmost); If SIGUSR1 is delivered before sigsuspend, the process still suspends and deadlocks until another SIGUSR1 is delivered

sigsuspend – Example 2 static volatile sig_atomic_t sigreceived = 0 sigset_t maskall, maskmost, maskold int signum = SIGUSR1; sigfillset(&maskall); sigfillset(&maskmost); sigdelset(&maskmost, signum); sigprocmask(SIG_SETMASK, &maskall, &maskold); if (sigreceived == 0) sigsuspend(&maskmost); sigprocmask(SIG_SETMASK, &maskold, NULL); Assume that sigreceived is set to 1 at the end of an interrupt handling routine called on SIGUSR1

sigsuspend – Example 3 static volatile sig_atomic-t sigreceived = 0; /* external static variable */ … sigset_t maskblocked, maskold, maskunblocked; int signum = SIGUSR1; sigprocmask(SIG_SETMAK, NULL, &maskblocked); sigprocmask(SIG_SETMASK, NULL, &maskunblocked); sigaddset(&maskblocked,signum); sigdelset(&maskunblocked, signum); sigprocmask(SIG_BLOCK, &maskblocked, maskold); while(sigreceived == 0) sigsuspend(&maskunblocked); sigprocmask(SIG_SETMASK, &maskold, NULL);

sigsuspend – Example 4 static volatile sig_atomic-t sigreceived = 0; /* external static variable */ … sigset_t masknew, maskold; int signum = SIGUSR1; sigprocmask(SIG_SETMASK, NULL, &masknew); sigaddset(&masknew, signum); sigprocmask(SIG_SETMASK, &masknew, maskold); sigdelset(&masknew, signum); while(sigreceived == 0) sigsuspend(&masknew); sigprocmask(SIG_SETMASK, &maskold, NULL);

sigsuspend – Example 5 int simplesuspend(void) { … if ((sigprocmask(SIG_SETMASK,NULL,&maskblocked) == -1) || (sigaddset(&maskblocked,signum) == -1) || (sigprocmask(SIG_SETMASK,NULL,&maskunblocked) == -1) || (sigdelset(&maskunblocked,signum) == -1) || (sigprocmask(SIG_SETMASK,&maskblocked,&maskold) == -1)) return –1; while(sigreceived == 0) sigsuspend(&maskunblocked); sigreceived = 0 return sigprocmask(SIG-SETMASK, &maskold,NULL); }

sigwait SYNOPSIS #include <signal.h> int sigwait(const sigset_t *restrict sigmask, int *restrict signo); POSIX:CX Blocks until any signal specified by sigmask is pending Then it removes that signal from the set of pending signals and unblocks The number of the signal removed from pending signals is stored at location signo

sigwait – Counts SIGUSR1 Occurances int main(void) { int signalcount = 0; int signo; int signum = SIGUSR1; sigset_t sigset; if((sigemptyset(&sigset) == -1) || (sigaddset(&sigset,signum) == -1) || (sigprocmask(SIG_BLOCK, &sigset,NULL) == -1)) perror(“Failed to block signals before sigwait”); fprintf(stderr,”This process has ID %ld\n”,(long)getpid()); for(;;) { if(sigwait(&sigset,&signo)== -1) { perror(“Failed to wait using sigwait”); return 1; } signalcount++; fprintf(stderr,”Number of signals so far: %d\n”, signalcount); } }

Biff get_file_size /* Return the size of file if no error. Otherwise if * file does not exist return 0 otherwise return -1. */ long get_file_size(const char *filename) { struct stat buf; if (stat(filename, &buf) == -1) { if (errno == ENOENT) return 0; else return -1; } return (long)buf.st_size; } /* Notify the user that mail has arrived */ void send_mail_notification() { fprintf(stderr, "Mail has arrived\007\n"); }

Biff Interrupt Handlers /* Turn on mail notification */ void turn_notify_on(int s) { notifyflag = 1; } /* Turn off mail notification */ void turn_notify_off(int s) { notifyflag = 0; }

Biff notify_of_mail /* Continuously check for mail and notify user of new mail */ int notify_of_mail(const char *filename) { … sigemptyset(&emptyset); sigemptyset(&blockset); sigaddset(&blockset, SIGUSR1); sigaddset(&blockset, SIGUSR2); get mail; if mail is empty return(1) else call send_mail_notification; sleep(SLEEPTIME); for( ; ; ) { if (sigprocmask(SIG_BLOCK, &blockset, NULL) < 0) return 1; while (notifyflag == 0) sigsuspend(&emptyset); if (sigprocmask(SIG_SETMASK, &emptyset, NULL) < 0) return 1; compare new mail with old mail; if new mail is larger call send_mail_notification; sleep(SLEEPTIME); } }

Biff main() void main(void) { … newact.sa_handler = turn_notify_on; newact.sa_flags = 0; sigemptyset(&newact.sa_mask); sigaddset(&newact.sa_mask, SIGUSR1); sigaddset(&newact.sa_mask, SIGUSR2); if (sigaction(SIGUSR1, &newact, NULL) < 0) perror("Could not set signal to turn on notification"); newact.sa_handler = turn_notify_off; if (sigaction(SIGUSR2, &newact, NULL) < 0) perror("Could not set signal to turn off notification"); notify_of_mail(mailfile); fprintf(stderr, "Fatal error, terminating program\n"); exit(1); }

Interrupted read … while (retval = read(fd, buf, size), retval == -1 && errno == EINTR) ; if (retval == -1) { /* handle errors here */ Notice the use of the comma expression.

Timeout read from pipe … alarm(10); if (read(fd, buf, size) < 0) { if (errno == EINTR) fprintf(stderr,"Timeout occurred\n"); /* handle timeout here */ else fprintf(stderr,"An error occurred\n"); /* handle other errors here */ } alarm(0); Alarm signal is assumed to be caught and does NOT terminate the program.

Async-Signal Safe A function is async-signal safe if it can be safely called within a signal handler Functions are NOT async-signal safe if they Use static data structures Call malloc or free Use global data structures in a non-reentrant way A single process cannot execute two occurrences of these calls concurrently Signals add concurrency to a program

Signal Handling Rules When in doubt, explicitly restart system calls within program Do not use functions that are not async-signal safe Analyze interactions – block signals that can cause unwanted interactions

Async-Signal Safe Functions _exit() fstat() read() sysconf() access() getegid() rename() tcdrain() alarm() geteuid() rmdir() tcflow() cfgetispeed() getgid() setgid() tcflush() cfgetospeed() setgroups() setpgid() tcgetattr() cfsetispeed() getpgrp() setsid() tcsendbreak() cfsetospeed() getpid() setuid() tcgetpgrp() chdir() getppid() sigaction() tcsetattr() chmod() getuid() sigaddset() tcsetpgrp() chown() kill() sigdelset() time() close() link() sigemptyset() times() creat() lseek() umask() dup2() mkdir() sigfillset() uname() dup() mkfifo() sigismember() unlink() execle() open() sigpending() utime execve() pathconf() sigprocmask() wait() fcntl() pause() sleep() waitpid() fork() pipe() stat() write()

… static volatile sig_atomic_t jumpok = 0; static sigjmp_buf jmpbuf; void int_handler(int signo) { if (jumpok == 0) return; siglongjmp(jmpbuf, 1); } void main(void) { struct sigaction act; int i; … act.sa_handler = int_handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; if (sigaction(SIGINT, &act, NULL) < 0) { perror("Error setting up SIGINT handler"); exit(1); } … if (sigsetjmp(jmpbuf, 1)) fprintf(stderr, "Returned to main loop due to ^c\n"); … jumpok = 1; /* start of main loop */ … } siglongjump