0% found this document useful (0 votes)
21 views53 pages

计算机操作系统 (第四版) 汤小丹课后答案完整版

The document outlines various aspects of operating systems (OS), including their structure, different types like Windows and UNIX, and concepts related to process management such as semaphores and mutexes. It discusses producer-consumer problems, scheduling algorithms, and memory management techniques like LRU and Clock algorithms. Additionally, it covers CPU and I/O interactions, as well as resource allocation strategies in concurrent systems.

Uploaded by

issunsun1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views53 pages

计算机操作系统 (第四版) 汤小丹课后答案完整版

The document outlines various aspects of operating systems (OS), including their structure, different types like Windows and UNIX, and concepts related to process management such as semaphores and mutexes. It discusses producer-consumer problems, scheduling algorithms, and memory management techniques like LRU and Clock algorithms. Additionally, it covers CPU and I/O interactions, as well as resource allocation strategies in concurrent systems.

Uploaded by

issunsun1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

1 OS

1 2 3 4

2 OS

1 OS

2 OS

3 OS

3 OS

OS I/O

OS

5 I/O I/O

I/O

I/O

CPU

8 OS
OS

10 8 16

CP/M MS-DOS.

11 Windows OS

1 Microsoft Windows 1.0

2 Windows 95 16 /32 32

3 Windows 98 16 /32 Windows

4 Windows XP Windows2000

Luna

5 Windows Vista WindowsAero

Windows IndexingService

12

100

13 OS

14
1

15 ?

16

: I/O I/O CPU I/O

I/O I/O .

17

18

19

1 OS

OS

2
20 OS /

C/S

21 OS

1 2 / 3

22 OS

OS

23

24

1.

(Precedence Graph) DAG(DirectedAcyclic

Graph)

2. :

S1=a =x+y; S2=b =z+1; S3=c =a b S4=w =c+1;

3.

5 ?
:

6 ?

(1)

(2) OS

(3)

7 PCB PCB

PCB

OS PCB

1 CPU

3 I/O

4 I/O

5/48

07 G09 5/48

10

11

12

I/O
13

1 OS Creat()

2 PCB

5 .

14

1 PCB PCB

5 PCB

15

a. b. c. d. .

16

1 A B A

B A B A

2 A B

A B

A B

17

"

" " "


18.

19. wait signal

wait(S) S.value>0 wait

S.value:=S.value-1 S.value<0 block

S.L

signal(S) signal

S.value:=S.value+1 1 S. value 0

wakeup S.L

20

21

mutex

1 CS wait(mutex) signal(mutex)

mutex

wait wait

mutex wait

mutex signal

Var mutex: semaphore:=1

begin

parbegin

process 1: begin

repeat

wait(mutex)

critical section

signal(mutex)

remainder section

until false

end

process 2: begin
repeat

wait(mutex)

critical section

signal(mutex)

remainder section

until false

end

parend

22 2-17

a Var a, b, c, d, e, f, g, h; semaphore:= 0, 0,0, 0, 0, 0, 0, 0;

begin

parbegin

begin S1; signal(a); signal(b); end;

begin wait(a); S2; signal(c); signal(d); end;

begin wait(b); S3; signal(e); end;

begin wait(c); S4; signal(f); end;

begin wait(d); S5; signal(g); end;

begin wait(e); S6; signal(h); end;

begin wait(f); wait(g); wait(h); S7; end;

parend

end

b Var a, b, c, d, e, f, g, h,i,j; semaphore:= 0,0, 0, 0, 0, 0, 0,0,0, 0;

begin

parbegin

begin S1; signal(a); signal(b); end;

begin wait(a); S2; signal(c); signal(d); end;

begin wait(b); S3; signal(e); signal(f); end;

begin wait(c); S4; signal(g); end;

begin wait(d); S5; signal(h); end;

begin wait(e); S6; signal(i); end;

begin wait(f); S7; signal(j); end;

begin wait(g);wait(h); wait(i); wait(j); S8;end;


parend

end

23 signal(full) signal(empty),

signal(full) full

full 0 wait(full)

signal(empty) n

empty=0 full=n empty

empty 0 n

24 wait wait(full) wait(mutex)

signal(mutex) signal full

wait(full) wait(mutex)

wait(mutex) wait(empty)

signal(empty)

signal(mutex) wait(mutex)

signal(mutex) signal(full)

25 W W=1 W=0

lock(W): while W=1 do no-op

W:=1;

unlock(W): W:=0;

lock(W): W:=W+1;

if(W>1) then block(W, L)

unlock(W): W:=W-1;

if(W>0) then wakeup(W, L)

Var W:semaphore:=0

begin

repeat

lock(W);
critical section

unlock(W);

remainder section

until false;

end

26 :

producer:

begin

repeat

producer an item in nextp;

wait(mutex);

wait(full);

buffer(in):=nextp;

signal(mutex);

until false;

end

consumer:

begin

repeat

wait(mutex);

wait(empty);

nextc:=buffer(out);

out:=out+1;

signal(mutex);

consumer item in nextc;

until false;

end

27 .

Var chopstick:array[0, ,4] of semaphore;


1 i

Repeat

Wait(chopstick[i]);

Wait(. chopstick[(i+1) mod 5]);

Ea.t ;

Signal(chopstick[i]);

Signal(chopstick[(i+1) mod 5])

Ea.t ;

Think;

Until false;

28

a. Var mutex, empty, full: semaphore:=1, 1, 0;

gather:

begin

repeat

gather data in nextp;

wait(empty);

wait(mutex);

buffer:=nextp;

signal(mutex);

signal(full);

until false;

end

compute:

begin

repeat
wait(full);

wait(mutex);

nextc:=buffer;

signal(mutex);

signal(empty);

compute data in nextc;

until false;

end

b. Var empty, full: semaphore:=1, 0;

gather:

begin

repeat

gather data in nextp;

wait(empty);

buffer:=nextp;

signal(full);

until false;

end

compute:

begin

repeat

wait(full); nextc:=buffer;

signal(empty);

compute data in nextc;

until false;

end

29
condition

30

ProclucerConsumer

1 Put item

count count n

2 get item count 0

PC

type producer-consumer =monitor

Var in,out,count:integer;

buffer:array[0, -1,n]of item;

notfull notempty:condition;

procedure entry dot(item)

begin

if count>=n then not full.wait;

buffer(in):=nextp;

in:=(in+1)mod n;

count:=count+1;

if notempty.queue then notempty.signal;

end

procedure entry get(item)

begin

if count<=0 then not full.wait;

nextc:=buffer(out);

out:=(out+1)mod n;

count:=count-1;

if notfull.quene then notfull.signal;

end

begin in:=out:=0;

count:=0

end

producer: begin

pepeat
produce an inem in nestp

PC.put(item);

until false;

end

consumer: begin

repeat

PC.get(item);

consume the item in enxtc;

until false;

end

31 AND AND

wait AND

var mutex,empty,full: semaphore:=1,n,0;

buffer: array[0,...,n-1] of item;

in,out: integer:=0,0;

begin

parbegin

producer: begin

repeat

produce an item in nextp;

wait(empty);

wait(s1,s2,s3,...,sn); //s1,s2,...,sn empty

wait(mutex);

buffer(in):=nextp;

in:=(in+1) mod n;

signal(mutex);

signal(full);

signal(s1,s2,s3,...,sn);

until false;

end

consumer: begin
repeat

wait(full);

wait(k1,k2,k3,...,kn); //k1,k2,...,kn full

wait(mutex);

nextc:=buffer(out);

out:=(out+1) mod n;

signal(mutex);

signal(empty);

signal(k1,k2,k3,...,kn);

consume the item in nextc;

until false;

end

parend

end

32

AND

Var RN integer;

L,mx: semaphore:=RN,1;

begin

parbegin

reader:begin

repeat

Swait(L,1,1);

Swait(mx,1,1);

perform read operation;

Ssignal(L,1);

until false

end

writer:begin

repeat

Swait(mx,1,1;L,RN,0);

perform write operation;

Ssignal(mx,1);
until false

end

parend

end

33

34

35

1 2 3 4

36 OS

OS

CPU ,

37

1) 2 3 4

38.

1 OS

39. OS

40

OS

41
1

42

LWP

LWP

43

PTDA TCB

TCB TCB PTDA

TCB

TCB TCB

3 JCB

JCB
JCB 1) 2) 3) 4) CPU

I/O 5) 6) 7)

8) 9) 10) 11) 12)

1 2 3

EDF LLF

10 FCFS SPF

FCFS

/ SPF

/ /

11

12
/

13

3 1 2 n

14 CPU

15

16

3-9

1 1

2 3 3 2 1

3 4 2 3

4 2

3-9 EDF

17

( )

200 ms

100 ms 100 ms

( ) 100 ms 400 ms

150 ms 250 ms

18
19

20

21 P0 Request(0,2,0) Request(0,1,0)

( )

1 10 5 7 T0

Requst0(0,1,0)<=Need0(7,4,3);

Requst0(0,1,0)<=Available(2,3,0);

P0 Available 0 Allocation 0 Need 0

3 P0 P0 Requst0(0,1,0),

Requst0(0,1,0)<=Need0(7,4,3);

Requst0(0,1,0)<=Available(2,3,0);

P0

22 1 2 P2

Request(1,2,2,2)

2 P2 Request 1,2,2,2 (

)
1 {P0,P3,P4,P1,P2}

Request(1,2,2,2) <=Need2(2,3,5,6);

Request(1,2,2,2) <=Available2(1,3,5,4) Available2(1,6,2,2)

P2 Available2 Allocation2 Need2

{P2,P0,P1,P3,P4}

Cache

CPU

3 P120

Linker

Load Module

0 1

6
7

8 x

10

11

12
(1)

(2)

13

14

1) 0

2)

3)

4)

5)

15

CPU P

OS

16

17

, ; ,
, ,

3 ,

18 .

( )

19

20

1 2 3

21

22

P A M

P A

23

2
3 UNIX

UNIX

24

LRU

Clock

25

( )

26 LRU 4,3,

2 ,1 , 4 , 3 , 5 , 4 ,3 , 2 , 1 ,5 M 3 4

? ?( )

M 3 7 : 7/12=0.583

M 4 4 : 4/12=0.333.

-------

M 3 9 : 9/12=3/4

M 4 10 : 10/12=5/6.

27 LRU ?

28 Clock .

Clock

29

2 0 PSW

4
5

30 ?

Count Count

1 Count 1 0

I/O

2 CPU

I/O I/O

5 VESA PCI

VESA 32 132Mb/s

486 2~4

Pentium

PCI CPU

10 CPU
132Mb/s ISA EISA Pentium 64

6 I/O

I/O I/O I/O

DMA I/O

7 I/O

I/O

(1) I/O I/O I/O

(2) I/O

(3) DMA I/O DMA

(4) I/O

8 DMA

DMA CPU

CR

MAR

DC DMA I/O DMA

CPU DMA DMA

1 CPU I/O

2 CPU

3 CPU I/O

10 max C,T +M?

M CPU C

CPU

max(C, T) + M

11 max T,C ?

T M
max(C+M,T) M

max(C,T)

12

13

GetBuf(EmptyQueue) EmptyQueue

Hin PutBuf(InputQueue,Hin)

InputQueue

GetBuf(OutputQueue)

Sout

PutBuf(EmptyQueue,Sout) EmptyQueue

14

I/O I/O

CPU I/O

I/O I/O

I/O

15
1 2

I/O

16

(1) I/O

(2) I/O

(3)

(4)

(5)

(6)

17

18 SPOOLing

SPOOLing SPi

SPo

19 SPOOLing I/O

SPOOLing I/O

20
1 I/O

2 I/O

3 I/O

4 ROM

21

2 I/O I/O

3 I/O I/O I/O

5 I/O

22.

(1)

(2) CPU

(3)

(4)

(5)

23.

Ts Tr Tt

1 Ts s n
Ts = m n+s

2 Tr 15000r/min Tr 2ms; 300

600r/min Tr 50~100ms

3 Tt
Tt / b

Tt = b/rN

24.

(1)

(2)

(3)

25.

I/O 4-6 I/O

I/O
26.

4-6

27

RAM

28.

RAID

RAID

I/O

I/O I/O

3
1 /

N/2

N N /2

10 MS-DOS A B A 11 12 16 14 B 13

18 20 A B FAT
11 NTFS

NTFS

12 MS-DOS FAT 64K

512B 512MB

512MB/512B=1M 1M

64K 512MB

13

(1) (2) (3)

14 UNIX 1KB 4 256

9999 18000 420000

, [ ]/[

] FCB 0-9 10

11 12

1 9999/1024=9 783 9 9

783

2 18000/1024=17 592 10<17<10+256 10

592

3 420000/1024=410 160 10+256<410 11

160

15

16 UNIX
UNIXSystem BSD UNIX 13 iaddr(0) iaddr(12)

17

18

19

20 Hash

Hash

Hash

21 Hash

Hash

Hash

22

DGA

23 6-33 1KB

0 i=3 j=3

b= 3-1 *16+3=35

map[3 3]=1

0 i=4 j=7

55 map[i j]=1
24 500 32

2 i j

3 /

1 INT 500/32 =16

2 b=(i-1)*32+j

3 map[i,j]=1

map[i,j]=0

25 UNIX

UNIX

26

27

28

29

30

31

Ti Ti

redo undo

32
Ti Q Q Q Ti

Q Ti Q Ti Q

33

34

0 N

1 K 0 K

2 K 2 K

3 K 0 K

1 login password

2 format diskcopy diskcomp

backup

3 type copy comp rename

erase
4 mkdir dir rmdir

tree chdir

5 > <, | /, .bat

>

<

MS-DOS UNIX

"|" command1 |command2 | |commandn

1 2 3

4 5

8 MS-DOS COMMAND.COM

COMMAND.COM

1 Autoexec.bat

exec

4 2

9 UNIX

mv mv oldname newname

10

cd .. cd .

11. file1 file2

: $catfile1>>file4
12. mail write ?

: mail UNIX write

13. ?

14

2 /

15

16

2 CPU PSW PC

UNIX CHMK

User U.U-arg() MS-DOS INT21

17. open
:

18. UNIX

: unlink i.link 1

i.link 1 0

19. IPC

: IPC

1 msgget,msgsend,msgrcv

2 shmget,shmid,shmdt

20. trap.S

UNIX V trap.S

trap.S

trap.S

21. UNIX CPU

CHMK (CHange Mode toKernel

R0 CHMK

(PSL) PC (code)

trap.S trap.S

trap.S type usp

CPU R0 R11

R0 R11 1

22. trap.C

trap.C C 12

trap.C

23. UNIX

UNIX sysent[]

trap.C
1.

2.

3.

4.

1 2

1 FDDI 2 100 BASE-T

5. LAN

LAN

LAN LAN WAN WAN LAN

1 2

9 TCP/IP

TCP/IP 4

1 OSI FTP Telnet DNS


2 OSI

TCP UDP

3 OSI IP

ARP IGMP ICMP

4 OSI

10 IP IP TCP

1 IP IP

2 TCP TCP IP

TCP

11. MAC IEEE 802.2 IEEE802.3 IEEE 802.3u IEEE

802.2z IEEE 802.5 IEEE802.6

IEEE 802.2 IEEE 802.3

IEEE 802.3u IEEE 802.2z

IEEE 802.5 IEEE 802.6

12. OSI/RM

OSI/RM

13.

14.ISO OSI/RM

OSI/RM 7
15. /

1 2

3 4

16..

C/S

C/S

17. C/S

2 C/S

C S C/S

18. Internet /

Internet / Web

Web Web C/S

19. C/S

2 3

1 2

20.

21.

22.

23.

24.

A B C

D E

25.

26.
TCP/IP

27. ? ?

E-mail, @

MIME SMTP E-mail

28.

Internet FTP

1 FTP FTP

2 FTP Internet

29.

E-mail

Internet FTP

30.

31.

32. Internet

1 2 3 4

33. WWW

WWW Word Wide Web Web

Web

34. BBS
BBS Bulletin BoardSystem BBS BBS

BBS

Internet BBS

BBS BBS

35. Internet

Internet

"." cctv.com

"." "."

TLD "." SLD

36.

IP IP

IP DNS

IP

DNS UDP

IP

IP

37. Internet

WEB IE firefox Chrome

38. /

/ B/S Browser/Server

Server Browse WWW Script

(VBScript JavaScript ) ActiveX

B S

Web Server Windows

B/S

HTML
1

8 D1( ) C1( )

C2( ) B1 B2 B3 A1 A2

5.

publickey privatekey

6.

How are you Ipx bsf zpv

7. DES

64 X0 32 L0

32 R0

X0 16 56 Ki

16 32 32

8.

9
1 A Kda P DKda P

2 A B Keb DKda P EKeb


DKda P B

3 B Kdb DKda EKeb DKda P =DKda P

4 B A Kea DKda P

EKeb DKda P =P 10

(1) A CA A A

(2) CA A A

A CA CA CA

(3) A B A B

(4) B CA CA B CA

B B B

(5) B CA B

A A A

(6) B A A

11

12 -

- FEP

13.

1 2 3 4

14

15.

IC

16.
17.

18

19 SSL

SSL Internet SSL

SSL

SSL

20.

21.

switch

access(i,j) i j D1 D2 S

D1 D2 D2 D3 S D2

D3 D3 D1

22.

i j acess(i,j) i

acess(i,j)

acess(i,j)

23.

i j i j

24.

access(i,j)

C Di Qj
25

ACL

26

27

28.

29.

30.

(1) (2)

(3) (4)

31.

(1) (2)

(3) (4)

(5) (6)

32.

(1) (2)

1 UNIX

2 UNIX
UNIX OS OS

shell

3 UNIX PCB

UNIX PCB U

5 UNIX

1 fork

2 exit

3 exec

4 wait

7 exit

Unix exit

exit

exit

8 UNIX

UNIX

= CPU /2 +

9 sleep

sleep

10

:
11

proc

signal sig func

func=1 func=0 func 0 1 func

12

pipe pipe

pipe

mknod

13

1 pipe

14

msgctl( ) msgsnd( ) msgrcv( )

msgctl( )

msgsnd( )

msgrcv( )

15

shmget() shmctl() shmat()

shmget( ) key size

shmctl( )

shmat( ) shmaddr

16 shmget

(1) key shmid

(2) key flag IPC_CREAT size


(3) x ???
l/

shmid

17

senget( ) semop( ) semget()

semop( )

18

sem_op 3

sem_op V sem_op

(sem_flg&IPC_NOWAIT)

19 UNIX

UNIX V

20

1 file

I/O

21

22

I/O getcf
bp 6

putcf

bp cfreelist

23

UNIX

1 2

24 getblk() getblk(dev blkno)

getblk() getblk(dev blkno)

dev blkno

getblk

25 gdopen gdstart gdstartegy gdintr

gdopen

gdstart

gdstartegy I/O

gdintr I/O

26 UNIX

bread breada

bwrite bawrite bdwrite

27 UNIX

A B

C D

28 UNIX

UNIX

29 UNIX

1 10 9999

9999/1024=9 783 9 i-addr(9)

783 9999
2 10 10+256

18000 18000/1024=17 592 10<17<10+256

i-addr(10) 10

17 i-addr(10) 428 17-10=7

592 18000

3 266 64266

420000 266<410<64266

i-addr(11) 266

160 420000

30

ialloc i i

i i i 1

ifree i i

i i 1

31

creat

32

unlink nlink 0

You might also like