lecture22 - CIS 450 Computer Architecture and Organization...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 450 – Computer Architecture and Organization Lecture 22: Virtual Memory Mitch Neilsen ([email protected] ) 219D Nichols Hall
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics ± Signals z Signal Handlers ± Non-local Jumps ± Virtual Memory z Address Spaces z Motivations for Virtual Memory (VM) z Address translation z Accelerating translation with TLBs z Read Chapter 10
Background image of page 2
Installing Signal Handlers The signal function modifies the default action associated with the receipt of signal signum : ± handler_t *signal(int signum, handler_t *handler) Different values for handler : ± SIG_IGN: ignore signals of type signum ± SIG_DFL: revert to the default action on receipt of signals of type signum . ± Otherwise, handler is the address of a signal handler z Called when process receives signal of type signum z Referred to as “ installing ” the handler. z Executing handler is called “ catching ”or“ handling ” the signal. z When the handler executes its return statement, control passes back to instruction in the control flow of the process that was interrupted by receipt of the signal.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Signal Handling Example void int_handler(int sig) { printf("Process %d received signal %d\n", getpid(), sig); exit(0); } void fork13() { pid_t pid[N]; int i, child_status; signal(SIGINT, int_handler); . . . } linux> ./forks 13 Killing process 24973 Killing process 24974 Killing process 24975 Killing process 24976 Killing process 24977 Process 24977 received signal 2 Child 24977 terminated with exit status 0 Process 24976 received signal 2 Child 24976 terminated with exit status 0 Process 24975 received signal 2 Child 24975 terminated with exit status 0 Process 24974 received signal 2 Child 24974 terminated with exit status 0 Process 24973 received signal 2 Child 24973 terminated with exit status 0 linux>
Background image of page 4
Signal Handler Funkiness Pending signals are not queued ± For each signal type, just have single bit indicating whether or not signal is pending ± Even if multiple processes have sent this signal int ccount = 0; void child_handler(int sig) { int child_status; pid_t pid = wait(&child_status); ccount--; printf("Received signal %d from process %d\n", sig, pid); } void fork14() { pid_t pid[N]; int i, child_status; ccount = N; signal(SIGCHLD, child_handler); for (i = 0; i < N; i++) if ((pid[i] = fork()) == 0) { /* Child: Exit */ exit(0); } while (ccount > 0) pause();/* Suspend until signal occurs */ }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Living With Non-Queuing Signals Must check for all terminated jobs ± Typically loop with wait void child_handler2(int sig) { int child_status; pid_t pid; while ((pid = waitpid(-1, &child_status, WNOHANG)) > 0) { ccount--; printf("Received signal %d from process %d\n", sig, pid); } } void fork15() { . . . signal(SIGCHLD, child_handler2); . . . }
Background image of page 6
Signal Handler Funkiness (Cont.) Signal arrival during long system calls (say a read ) ± Signal handler interrupts read() call ± Linux: upon return from signal handler, the read() call is restarted automatically ± Some other flavors of Unix can cause the read() call to fail with an EINTER error number ( errno ); in this case, the application program can restart the slow system call Subtle differences like these complicate the writing of portable code that uses signals.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A Program That Reacts to Externally Generated Events (ctrl-c) #include <stdlib.h> #include <stdio.h>
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/09/2008 for the course CIS 450 taught by Professor Neilsen,mitch during the Spring '08 term at Kansas State University.

Page1 / 51

lecture22 - CIS 450 Computer Architecture and Organization...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online