Download - 第十章 UNIX 系统内核结构
-
UNIX UNIX Maurice J.Bach
-
UNIX; ,,,UNIX(,),,
-
UNIX
-
10.1 UNIX1. UNIX1) 2) 3) 4) 5)
-
UNIXUNIX
-
I/O Shell UNIXUNIX
-
2. UNIX 10-1 UNIX
-
1) (1) (2) (3) (4)
-
2) (1) (2) (3)
-
10.2 UNIX (1) (2) U (3) (4) 2.1
-
1. (Process Table Entry) (1) (PID) (2) (UID) (3) (4) (5) U (6) (7) (8) (9) nice (10) P-Link (11) U
-
2. U(U Area) (1) (2) u-ruid(real user ID) (3) u-euid(effective user ID) (4) (5) (6) (7) I/O (8) (9) (10) (11)
-
3. (System Region Table) (1) (2) (3) (4) (5)
-
4. (Per Process Region Table) 10-2
-
2.2 1.
-
12345
678910-4
-
1
-
20#
-
3
-
2. UNIX
PCPSWPCB
-
0#0#1#12n. . .. . .2.3
-
0# 1# 1# UNIX
-
1. schedPID=0 UNIX swapmemory() 2. initPID=1 bootlogin ancestor schedancestor 3. vhandPID=2 memoryswap 4. dbflushPID=3 buffer cache 5. kmdaemonPID=4 6. htepi_daemonPID=5 ht filesystem driver
-
1. fork(1) (2) (3) (4) (5) (6)
-
main(){pid_t pid;pid=fork();if(pid==0)exec(program);else if(pid>0)wait();}(1) (2) (3) (4) (5) (6)
-
2. execint execv(path,argv)char *path,*argv[]int execl(path,arg0[,arg1,...,argn], 0)char * path,*arg0,*arg1,.......,*argn
-
3. exit exitexit(1) (2) (3) (4)
-
4. wait wait wait
-
main(){int i;while((i=fork()==-1);if (i) { printf(Its parent process.\n);wait();printf(My child process,Id number%d exited.\n,i);exit();}else printf(It is child process);printf(It is parent or child process);}ID331
-
1Its parent processIt is child processIt is parent or child processMy child process,Id number 33 exited
-
2It is child processIt is parent or child processIts parent processMy child process,Id number 33 exited3It is child processIts parent processIt is parent or child processMy child process,Id number 33 exited
-
2UN IX Amian() /*A*/{fork();fork();fork();}
-
mian() /*A*/{fork();fork();fork();}mian() /*B*/{fork();fork();fork();}
-
ABCEDFGH
-
3#include main(){char command[32];char *prompt=>;while (printf(%s,prompt),gets(command)!=NULL){if (fork()==0) execl(command,command,(char *) 0); else wait(); }}
-
24 UNIX CPU CPU
-
UNIX1CPU
0#swtch
-
Round Robin With Multiple Feedback)
-
N .....CPU
-
123) 45cpu
-
UNIXn+1 0n
-
Unix sys V,
-
Ppri= Pcpu/2+PUSER+Pnice+NZERO
Pcpu CPU
Pnice0~40nicePUSERNZERO
-
Pcpu/2=0
a) :Pcpu
b) :Pcpu2Pcpu/2CPU
-
,
-
0CPU0
user
-
10.3 1 sleepwakeup234UNIX V IPC
-
a.bc 3.1 sleepwakeup1. sleep
-
2. wakeup :
-
3.2 (signal) 1. 1~19PCB19
-
killint kill(pid,sig);pidpidpid 0 sig
-
signal(sig,func)func=1sigfunc=0 sigfunc 0/1func
-
func==1func==0corefunc 0/1
-
3.3 1. (Unnamed Pipes) pipe() (Named Pipes) mknod
-
2. pipe 2) 3) 4)
-
3.4-1
-
1. key
-
2) 10-6
-
msgget()int msgget(key,msgflag)
key: msgflagipc_CREATkeymsgid
msgid
-
msgsnd()msgsnd(msgid,msgp,msgsz,msgflg)
msgidmsgpmsgszmsgflg
-
msgrev()msgrev(msgid,msgp,msgsz,msgtpy,msgflg);msgid msgpmsgszmsgtpy msgflg
-
3.4-2 1. 10-7
-
UNIX
-
int shmget(key,size,shmflg);
key:sizeshmflg
shmid
-
shmatShmat(shmid,shmaddr,shmflg);
ShmidShmaddrShmflg
-
shmdt()
int shmdt(shmaddr);
shmaddr:
-
3.4-3 1) UNIXwaitsignalUNIXwaitsignalsemop( )semget( )semctl( )1.
-
2)
-
2. 1) semvalsempid
-
2) 10-8
-
3. 1) semget( ) semid
-
2) semop( ) semop semopsemopsemopsemop
-
10.4 10.4.1 1. 1) 10-9
-
2. 1) 1 2
-
2) 10-11
-
10.4.2 1. 012301231310
-
2. (1)1 (2) (3)
-
3. 64 KB1001
-
10.4.3 1. 2. 3.