DOC PREVIEW
U of I CS 241 - SIGNALS

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

SignalsAnnouncementsSolutions to Quiz 3Introduction to SignalsBasic Signal ConceptsHow Signals WorkExamples of POSIX Required SignalsSlide 8Generating SignalsCommand Line Generates SignalsCommand Line Generates SignalsTimers Generate SIGALRM SignalsExamples: Programming SignalsProgramming SignalsSignal MasksSignal SetsSlide 17Slide 18SIGPROCMASKExample: Initialize Signal Set:Example: Add SIGINT to Set of Blocked SignalsSummaryCopyright ©: Nahrstedt, Angrave, Abdelzaher 1SignalsCopyright ©: Nahrstedt, Angrave, Abdelzaher2AnnouncementsSMP3 due today 10pmSMP4 out next.Copyright ©: Nahrstedt, Angrave, Abdelzaher3Solutions toQuiz 3(C)while (lock)lock = 1;/* EnterCriticalSection; */ access shared variable;/* LeaveCriticalSection; */lock = 0;(B)int owner[2] = {false, false}…owner[my_process_id] = truewhile (owner[other_process_id]) { }access shared variable;owner[my_process_id] = false…(A)int owner[2]={false, false}int turn;…owner[my_process_id] = true;turn = other_process_id;while (owner[other_process_id] and (turn == other_process_id) { };access shared variablesowner[my_process_id] = false…CBAGuaranteesMutualExclusion?GuaranteesProgress?YESYES YESYES NONOCopyright ©: Nahrstedt, Angrave, Abdelzaher4Introduction to SignalsWhat is Signal? A signal is a software notification to a process of an event. Why do we need Signals? In systems we need to enable asynchronous eventsExamples of asynchronous events: Email message arrives on my machine – mailing agent (user) process should retrieveInvalid memory access happens – OS should inform scheduler to remove process from the processorAlarm clock goes on – process which sets the alarm should catch itCopyright ©: Nahrstedt, Angrave, Abdelzaher5Basic Signal ConceptsSignal is generated when the event that causes it occurs. Signal is delivered when a process receives it. The lifetime of a signal is the interval between its generation and delivery. Signal that is generated but not delivered is pending. Process catches signal if it executes a signal handler when the signal is delivered. Alternatively, a process can ignore a signal when it is delivered, that is to take no action. Process can temporarily prevent signal from being delivered by blocking it.Signal Mask contains the set of signals currently blocked.Copyright ©: Nahrstedt, Angrave, Abdelzaher6How Signals WorkSignal GeneratedProcessSignal HandlerSignal deliveredSignal not blockedSignal Caught by handlerReturn from Signal HandlerProcess ResumedSignalMaskSignalMaskSignalMaskCopyright ©: Nahrstedt, Angrave, Abdelzaher7Examples of POSIX Required SignalsSignal Description default action SIGABRT process abort implementation dependent SIGALRM alarm clock abnormal termination SIGBUS access undefined part of memory object implementation dependent SIGCHLD child terminated, stopped or continued ignore SIGILL invalid hardware instruction implementation dependent SIGINT interactive attention signal (usually ctrl-C) abnormal termination SIGKILL terminated (cannot be caught or ignored) abnormal terminationCopyright ©: Nahrstedt, Angrave, Abdelzaher8Signal Description default action SIGSEGV Invalid memory reference implementation dependent SIGSTOP Execution stopped stopSIGTERM termination Abnormal terminationSIGTSTP Terminal stop stop SIGTTIN Background process attempting read stop SIGTTOU Background process attempting writestopSIGURG High bandwidth data available on socketignore SIGUSR1 User-defined signal 1 abnormal terminationExamples of POSIX Required SignalsCopyright ©: Nahrstedt, Angrave, Abdelzaher9Generating SignalsSignal has a symbolic name starting with SIGSignal names are defined in signal.hUsers can generate signals (e.g., SIGUSR1)OS generates signals when certain errors occur (e.g., SIGSEGV – invalid memory reference)Specific calls generate signals such as alarm (e.g., SIGALRM)Copyright ©: Nahrstedt, Angrave, Abdelzaher10Command Line Generates Signals You can send a signal to a process from the command line using killkill -l will list the signals the system understandskill [-signal] pid will send a signal to a process. The optional argument may be a name or a number (default is SIGTERM).To unconditionally kill a process, use:kill -9 pid which is kill -SIGKILL pid.Copyright ©: Nahrstedt, Angrave, Abdelzaher11Command Line Generates SignalsCTRL-C is SIGINT (interactive attention signal CTRL-Z is SIGSTOP (execution stopped – cannot be ignored)CTRL-Y is SIGCONT (execution continued if stopped)CTRL-D is SIGQUIT (interactive termination: core dump)Copyright ©: Nahrstedt, Angrave, Abdelzaher12Timers Generate SIGALRM Signals#include <unistd.h>unsigned alarm (unsigned seconds);alarm(20) creates SIGALRM to calling process after 20 real time seconds.Calls are not stackedalarm(0) cancels alarmCopyright ©: Nahrstedt, Angrave, Abdelzaher13Examples: Programming SignalsFrom a program you can use the kill system call: #include <sys/types.h> #include <signal.h> int kill(pid_t pid, int sig); Example 8.4: send SIGUSR1 to process 3423: if (kill(3423, SIGUSR1) == -1) perror("Failed to send the SIGUSR1 signal"); Example 8.5: a child kills its parent: if (kill(getppid(), SIGTERM) == -1) perror ("Failed to kill parent");Copyright ©: Nahrstedt, Angrave, Abdelzaher14Programming SignalsExample 8.5: a process sends a signal to itself: if (raise(SIGUSR1) != 0) perror("Failed to raise SIGUSR1"); Example 8.8: kill an infinite loop after 10 seconds: int main(void) { alarm(10); for ( ; ; ) ; }Copyright ©: Nahrstedt, Angrave, Abdelzaher15Signal MasksProcess can temporarily prevent signal from being delivered by blocking it.Signal Mask contains a set of signals currently blocked.Important! Blocking a signal is different from ignoring signal. Why? When a process blocks a signal, the OS does not deliver signal until the process unblocks the signalA blocked signal is not delivered to a process until it is unblocked. When a process ignores signal, signal is delivered and the process handles it by throwing it away.Copyright ©: Nahrstedt, Angrave, Abdelzaher16Signal SetsSignal set is of type sigset_tSignal sets are manipulated by five functions:#include <signal.h> int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo); int


View Full Document

U of I CS 241 - SIGNALS

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download SIGNALS
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view SIGNALS and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view SIGNALS 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?