exceptions interrupts Computer Systems Bryant OHallaron 8 Keyboard
(exceptions & interrupts) הפרעות ופסיקות Computer Systems / Bryant & O’Hallaron ב 8 מבוסס ברובו על פרק
: נזכור את מבנה המערכת Keyboard Processor Interrupt controller Mouse Keyboard controller Modem Serial port controller Printer Parallel port controller Local/IO Bus Memory IDE disk controller SCSI controller Video adapter Network adapter Display Network SCSI bus disk – 5– CDROM
חריגות . חריגה היא העברת השליטה למ"ה כתגובה לאירוע כלשהו User Process event current next OS exception processing by exception handler exception return (optional) – 6–
Interrupt Vectors וקטורים של פסיקות Exception numbers code for exception handler 0 interrupt vector 0 1 2 n-1 . . . code for exception handler 1 code for exception handler 2 . . . code for exception handler n-1 – 7– לכל סוג אירוע יש מספר k חריגה ייחודי n מהווה את האינדקס לתוך jump table (a. k. a. interrupt vector) בטבלה מצביעה k הכניסה ה על פונקציה שנקראת exception handler ה interrupt )נקרא גם . (handler פונקציה זאת נקראת כל פעם . קורה k שאירוע n n n
Fault #2 דוגמה int a[1000]; main () { a[5000] = 13; } גישה לזיכרון המשתמש כותב למיקום לא חוקי בזיכרון . לתהליך SIGSEG נשלח סיגנל n . “segmentation fault” התהליך יוצא עם n User Process event movl OS page fault Detect invalid address Signal process – 15 – n
(Signals) אותות מ"ה + נשלחים על ידי התהליכים , אירועי תוכנה n מ"ה לתהליך אחר / נשלח מתהליך . לא נושא אינפורמציה נוספת. לכל אות יש מספר ייחודי n n Num. 2 Name SIGINT Default Terminate Description Interrupt from keyboard (cntl-c) 9 11 SIGKILL Terminate & Dump Kill program (cannot override or ignore) Segmentation violation 14 17 SIGALRM Terminate Ignore Timer signal Child stopped or terminated – 16 – SIGSEGV SIGCHLD
(ctrl-c) תוכנית שמגיבה לאותות חיצוניים #include <stdlib. h> #include <stdio. h> #include <signal. h> static void handler(int sig) { printf("You think hitting ctrl-c will stop me? n"); sleep(2); printf("Well. . . "); fflush(stdout); sleep(1); printf("OKn"); exit(0); } main() { signal(SIGINT, handler); /* installs ctl-c handler */ while(1) { } } – 19 –
- Slides: 20