Download presentation
Presentation is loading. Please wait.
Published byDora Holt Modified over 9 years ago
1
Signals
2
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 is interrupted r Events can arise from executing an instruction in the process’s instruction stream m Illegal instruction e.g., divide by zero m Illegal address e.g., accessing A[11] when there is no A[11]
3
Introduction r Events occur at any time and come from an external source m may be unrelated to the execution of the process m e.g., ctrl-D, ctrl-C, ctrl-Z r Upon receipt of a signal a process may take some action m Take a default action; or m Use a pre-defined signal handler
4
Introduction r Signal sending: m OS kernel updates info for destination process r Signal receiving: m kernel forces target process to handle signal r A process can block some signals 4 Operating system kernel processes devices signals interrupts
5
Dealing with Signals r Each signal type has a system-defined default action. m abort and dump core (SIGSEGV, SIGBUS, etc.) m ignore, stop, exit, continue r A process may choose to block or ignore some signal types.
6
Dealing with Signals:Actions r There are different actions that a process may choose to deal with a signal m Ignore Exceptions: SIGKILL and SIGSTOP m Default Different for different signals m Programmer-specified handler Used instead of default
7
Example int alarmflag=0; alarmHandler () { printf( “ An alarm clock signal was received\n ” ); alarmflag = 1; } main() { signal (SIGALRM, alarmHandler); alarm(3); printf( “ Alarm has been set\n ” ); while (!alarmflag) pause (); printf( “ Back from alarm signal handler\n ” ); } Suspends caller until signal Instructs OS kernel to send SIGALRM in 3 seconds Sets up signal handler
8
Signal Handling r The system call signal captures a specific function and associates it with a programmer-defined function r To use the signal system call requires that you include signal.h r The form of the signal system call does vary across different versions of Linux/Unix
9
9 Important Signals r SIGINT m Interrupt signal from terminal (ctrl-c) r SIGTSTP m Stop signal from terminal (ctrl-z) r SIGCHLD m A child process has stopped or terminated
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.