60 pause . 60 - , - wakeup, , pause, . - , (). - , . 8.3  : * , * , , * ; * , * , * "" , * (. ), * . , - - . - 243 , ( ). - , - , . - 8.9. +------------------------------------------------------------+ | #include | | #include | | #include | | | | main(argc,argv) | | int argc; | | char *argv[]; | | { | | extern unsigned alarm(); | | extern wakeup(); | | struct stat statbuf; | | time_t axtime; | | | | if (argc != 2) | | { | | printf(" 1 \n"); | | exit(); | | } | | | | axtime = (time_t) 0; | | for (;;) | | { | | /* */ | | if (stat(argv[1],&statbuf) == -1) | | { | | printf(" %s \n",argv[1]); | | exit(); | | } | | if (axtime != statbuf.st_atime) | | { | | printf(" %s \n",argv[1]); | | axtime = statbuf.st_atime; | | } | | signal(SIGALRM,wakeup); /* | | */ | | alarm(60); | | pause(); /* */| | } | | } | | | | wakeup() | | { | | } | +------------------------------------------------------------+ 8.8. , alarm 244 +------------------------------------------------------------+ | clock | | : | | : | | { | | ; /* -| | */ | | ( ) | | { | | ; | | callout, ; | | } | | ( ) | | -| | ; | | ( ) | | -| | ; | | ; | | ; | | ; | | ( 1 ,| | ) | | { | | ( ) | | { | | "", ; | | ; | | ( )| | ; | | } | | - | | ; | | } | | } | +------------------------------------------------------------+ 8.9. 8.3.1  , . - . 8.3.2 - , , . - , , , , " " (. 10.3.3). ( 8.9), - , , , , ( ) 245 . - ; - . - . , - . - , . +----------------------------+ +----------------------------+ | a() -2 | | a() -2 | +----------------------------+ +----------------------------+ | b() 3 | | b() 3 | +----------------------------+ +----------------------------+ | c() 10 | | f() 2 | +----------------------------+ +----------------------------+ | c() 8 | +----------------------------+ 8.10. 8.10 - . ( " " a ). , " " , . , f 5 : b " " , 2 ( b f - 5), " " c 8 ( c 13 ). , - . , . - " " . - , , , " " - , - , . , . , - . , , - . , - , . , " ", - . , , - 246 . , , " ", - , . - , " " - . , . , , a " ", -2 ( 8.10), , a , 2 . , b 2 , , a, " " b. 8.3.3  - , - . , . - ( , ); . - , - , , - , - - - . , , , , , . - , . +--------------------------------+ | | | | | bread 100 5 | | breada 150 0 | | bwrite 200 0 | | brelse 300 2 | | getblk 400 1 | | user - 2 | +--------------------------------+ 8.11. 8.11 . 10 , - , : 110, 330, 145, , 125, 440, 130, 320, 104. , - . , 20% (user) 50% bread . 247 , . , , , - , - , , - . , - . , . - [Weinberger 84] , "if-then" "else", - . , 50-200%, - . profil: profil(buff,bufsize,offset,scale); buff - , bufsize - , offset - (, - ), scale - . "scale" . , , - , Oxffff, , , Ox7fff, buff , Ox3fff - - .. , , . , , , offset , - bufsize scale. , 8.12, f g. , - signal, theend, , - ( main theend), , - , profil, , - . 10 AT&T 3B20 , - 8.13. f 204 ; f 12 , - AT&T 3B20 4 , f buf 51, 52 53. g buf c 54, 55 56. buf 46, 48 49 , - main. , , - , . profil - , - ; , , . 248 +------------------------------------------------------------+ | #include | | int buffer[4096]; | | main() | | { | | int offset,endof,scale,eff,gee,text; | | extern theend(),f(),g(); | | signal(SIGINT,theend); | | endof = (int) theend; | | offset = (int) main; | | /* */ | | text = (endof - offset + sizeof(int) - 1)/sizeof(int); | | scale = Oxffff; | | printf | | (" %d %d %d\n",| | offset,endof,text); | | eff = (int) f; | | gee = (int) g; | | printf("f %d g %d fdiff %d gdiff %d\n",eff,gee, | | eff-offset,gee-offset); | | profil(buffer,sizeof(int)*text,offset,scale); | | for (;;) | | { | | f(); | | g(); | | } | | } | | f() | | { | | } | | g() | | { | | } | | theend() | | { | | int i; | | for (i = 0; i < 4096; i++) | | if (buffer[i]) | | printf("buf[%d] = %d\n",i,buffer[i]); | | exit(); | | } | +------------------------------------------------------------+ 8.12. , profil +------------------------------------------------------+ | 212 440 57 | | f 416 g 428 fdiff 204 gdiff 216 | | buf[46] = 50 | | buf[48] = 8585216 | | buf[49] = 151 | | buf[51] = 12189799 | | buf[53] = 65 | | buf[54] = 10682455 | | buf[56] = 67 | +------------------------------------------------------+ 8.13. , - profil 249 8.3.4  , (- ). , . , . - . - , . - , - . - - wait, - , . - . - , , . , , 25 40 , , - 50 , 75 (50/5 + 25 + 40). - . , , , , - , . - . 8.3.5  - , . - time . fork, , - . , - stime , . 8.4  UNIX. - , . , , , , - . , - ( , ), , : - , , - . - nice - , . 250 , : , "". , - , , , , - , "" . - "" . 8.5  1. , , , . , , , , . . *2. - 1 . , - . - ? 3. UNIX - : decay() = max ( , -10); : decay() = .8 * ; : = /16 + ( ); 8.4, . 4. 8.4 , 60 100 - . . 5. , - , - . , ? , - shell' ? 6. wait - , . "" - ? 7. nice , : nice 6 nroff -mm big_memo > output , nice. 8. 8.4, , , nice A, 5 -5. 9. renice x y, x - (), y - nice - . 10. , 8.6. , - , A, 33% , , B, - 66% . - ? , - . 251 11. date. : , : date mmddhhmmyy () (, , , , ). , date 0911205084 11 1984 8:50 . 12. sleep: sleep(seconds); . , alarm pause. , alarm sleep ? : 1) alarm , - , 2) alarm sleep. *13. . - sleep alarm pause. , alarm , pause. ? ? 252