CS 241 System Programming: Timers & Signals
CS 241 System Programming: Timers & Signals
CS 241 System Programming: Timers & Signals
Discussion Section 5
20 Feb – 23 Feb
Outline
Review: Scheduling
Signals
Signal/Timer Handlers
pause(), sigwait()
POSIX:TMR Timers
clock_gettime()
nanosleep()
Scheduling (methods for MP2)
pthread_sigmask
Takes same parameters as sigprocmask
Only has effect on the sigmask for a single thread
Signal masks inherited during thread creation
Need to use in MP2
Block the timer signal in non-scheduler threads
Block resume signal in non-scheduler threads
(potentially) Block non-timer signals in scheduler
thread
Effect of a Generated Signal
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);
}}
Accessing the Clock