C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh
This presentation is the property of its rightful owner.
Sponsored Links
1 / 83

Câu 1: Chức năng, nhiệm vụ của hệ điều hành. Phân loại hệ điều hành PowerPoint PPT Presentation


  • 139 Views
  • Uploaded on
  • Presentation posted in: General

Câu 1: Chức năng, nhiệm vụ của hệ điều hành. Phân loại hệ điều hành. Định nghĩa - Hệ Điều Hành là hệ chương trình hoạt động giữa người sử dụng và phần cứng thiết bị của máy tính. - Hệ Điều Hành giúp thi hành các chương trình, làm cho máy tính dễ sử dụng và hiệu quả hơn. I. Khái niệm về HĐH.

Download Presentation

Câu 1: Chức năng, nhiệm vụ của hệ điều hành. Phân loại hệ điều hành

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

Cu 1: Chc nng, nhim v ca h iu hnh. Phn loi h iu hnh

nh ngha

- H iu Hnh l h chng trnh hot ng gia ngi s dng v phn cng thit b ca my tnh.

- H iu Hnh gip thi hnh cc chng trnh, lm cho my tnh d s dng v hiu qu hn.


I kh i ni m v h h

I. Khi nim v HH

Cc thnh phn ca mt h thng my tnh

- Phn cng: CPU, b nh, cc thit b nhp xut, cung cp cc ti nguyn tnh ton c bn cho h thng.

- H iu Hnh: iu khin v phi hp vic s dng phn cng cho nhng ng dng khc nhau ca nhiu ngi s dng khc nhau.

- Cc chng trnh ng dng: chng trnh dch, h thng c s d liu, cc tr chi, v cc ng dng thng mi. Xc nh ti nguyn no c s dng cho cc vn tnh ton ca ngi s dng.

- Ngi s dng:


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

Ngi

s dng 1

Ngi

s dng 2

Ngi

s dng 3

...

Ngi

s dng n

Cc chng trnh ng dng

Chng trnh dch

Hp ng

Son tho vn bn

...

C s

d liu

H iu Hnh

Phn cng


L ch s ph t tri n h i u h nh

Lch s pht trin H iu Hnh

- Th h 1 (1945 1955): My tnh ln, cha c H iu Hnh.

- Th h 2 (1955 1965): H thng x l theo l, thc hin cc cng vic tun t theo mt chng trnh nh trc. Chng trnh ny l tin thn ca H iu Hnh.

- Th h 3 (1965 1980): H iu Hnh a chng v H iu Hnh chia s thi gian.

- Th h 4 (1980 - 2004): H iu Hnh mng v H iu Hnh phn tn.


Ii ph n lo i h i u h nh

II. Phn loi H iu Hnh

  • H thng x l theo l (batch)

  • H thng x l a chng (multiprogram)

  • H thng x l a nhim (multitasking)

  • H thng a x l (h thng x l song song)

  • H thng x l phn tn

  • H thng x l thi gian thc

  • H thng nhng


H th ng x l theo l batch

H thng x l theo l (batch)

  • Ti mt thi im c mt cng vic trong b nh. Khi thc hin xong mt cng vic, cng vic khc s c t ng np vo v cho thc thi. C mt chng trnh, gi l b gim st, gim st vic thc hin dy cc cng vic mt cch t ng, chng trnh ny lun lun thng tr trong b nh chnh v chnh l H iu Hnh th s nht. VD: DOS


H th ng x l a ch ng multiprogram

H thng x l a chng (multiprogram)

  • Ti mt thi im c nhiu cng vic trong b nh v khi mt cng vic ang thc hin, nu c yu cu nhp/xut th CPU khng ngh m h thng s thc hin tip cng vic khc. H phi x l cc vn lp lch cho cng vic, lp lch cho b nh v cho CPU.


H th ng x l a nhi m multitasking

H thng x l a nhim (multitasking)

  • L m rng ca h a chng. Mi cng vic c thc hin lun phin qua c ch chuyn i CPU, thi gian mi ln chuyn i din ra rt nhanh nn c cm gic l cc cng vic ang c thi hnh cng lc.


H th ng a x l h th ng x l song song

H thng a x l (h thng x l song song)

C nhiu b x l cng chia s h thng ng truyn d liu cao tc, ng h, b nh v cc thit b ngoi vi.

- u im:

+ S hng hc ca mt b x l s khng nh hng n ton b h thng.

+ H thng s thc hin rt nhanh do thc hin cc cng vic ng thi trn cc b x l khc nhau.

- C hai loi h thng a x l:

+ H thng a x l i xng: mi b x l chy vi mt bn sao ca H iu Hnh v cc b x l l ngang cp.

+ H thng a x l bt i xng: c mt b x l chnh kim sot, lp lch cho cc b x l khc.

Vn ca a x l l g?


H th ng x l ph n t n

H thng x l phn tn

Tng t nh h thng a x l nhng mi b x l c b nh cc b ring. Cc b x l lin lc vi nhau thng qua cc ng truyn d liu. Mng LAN, WAN l h x l phn tn.

- u im:

+ Chia s ti nguyn: my in, tp tin

+ Tng tc tnh ton: phn chia cng vic tnh ton trn nhiu v tr khc nhau.

+ An ton: Nu mt v tr b hng, cc v tr khc vn tip tc lm vic.

+ Truyn thng tin d dng: download/upload file, gi/nhn mail,


H th ng x l th i gian th c

H thng x l thi gian thc

- H thng phi cho kt qu chnh xc trong khong thi gian nhanh nht.

- C hai loi:

+ H thng thi gian thc cng: cng vic c hon tt ng lc.

+ H thng thi gian thc mm: mi cng vic c mt u tin ring v s c thi hnh theo u tin.


Iii c c ch c n ng c a h i u h nh

III. Cc chc nng ca H iu Hnh

  • Qun l tin trnh

  • Qun l b nh chnh

  • Qun l b nh ph

  • Qun l h thng nhp xut

  • Qun l h thng tp tin

  • Bo v h thng

  • H thng dng lnh v giao din ngi dng

  • Qun l mng (h iu hnh mng)


C u 2 ti n tr nh process v ti u tr nh thread nguy n l chung th ng tin l u tr v ph n lo i ti u tr nh

* Cu 2: Tin trnh (process) v tiu trnh (thread): Nguyn l chung, thng tin lu tr v phn loi tiu trnh

  • Tin trnh (process)

    - Tin trnh l mt chng trnh ang x l, s hu mt ng cnh: khng gian a ch, mt con tr lnh, tp cc thanh ghi v stack. Tin trnh c th cn n mt s ti nguyn nh CPU, b nh chnh, cc tp tin v thit b nhp/xut.

    - H iu Hnh s dng b iu phi (scheduler) quyt nh thi im cn dng hot ng ca tin trnh ang x l v la chn tin trnh tip theo cn thc hin.


Ti u tr nh thread

Tiu trnh (thread)

  • Mt tin trnh c th chy trong mt tiu trnh (thread) n hoc to nhiu tiu trnh, mi tiu trnh thc hin mt chc nng no v thc thi ng thi cng bng cch chia s CPU. Cc tiu trnh trong cng mt tin trnh dng chung khng gian a ch tin trnh nhng c con tr lnh, tp cc thanh ghi v stack ring. Mt tiu trnh cng c th to lp cc tin trnh con, v nhn cc trng thi khc nhau nh mt tin trnh.

  • Cc tin trnh ch c th lin lc vi nhau thng qua cc c ch do H iu Hnh cung cp. Cc tiu trnh lin lc vi nhau d dng thng qua cc bin ton cc ca tin trnh.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

Multitasking

Process #1

B nh cc b

H iu hnh

Process #2

B nh cc b

Process #3

B nh cc b

B nh chia s


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

Multithreading Paradigm

Process #1

H iu hnh

Process #2

Thread #1

Bin cc b

Process #3

Thread #2

Bin cc b

B nh cc b

Thread #3

Bin cc b


C u 3 qu n l ti n tr nh c c tr ng th i v ch x l ti n tr nh

Cu 3: Qun l tin trnh: Cc trng thi v ch x l tin trnh

Khi mt tin trnh thc hin, n thay i trng thi. Ti mt thi im, mt tin trnh c th nhn trong mt cc trng thi sau y:

+ Newtin trnh mi c to.

+ Runningcc ch th ca tin trnh ang thc thi.

+ Waiting (blocked)tin trnh ch mt s kin no xy ra (nh hon thnh I/O, c cp pht mt ti nguyn, nhn tn hiu).

+ Ready tin trnh ch c cp pht CPU.

+ Terminated tin trnh kt thc x l.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

New

Terminated

Ready

Running

Waiting


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

1: Tin trnh mi to c a vo h thng (admitted).

2: B iu phi (scheduler) cp pht cho tin trnh mt khong thi gian s dng CPU (scheduler dispatch).

3: Tin trnh kt thc sau khi chy (exit).

4: Tin trnh yu cu mt ti nguyn nhng cha c p ng v ti nguyn cha sn sng; hoc tin trnh phi ch mt s kin hay thao tc nhp/xut (I/O hoc event wait).

5: B iu phi chn mt tin trnh khc x l (interrupt).

6: Ti nguyn m tin trnh yu cu tr nn sn sng cp pht; hay s kin hoc thao tc nhp/xut tin trnh ang i hon tt (I/O hoc event completion).

Ti mt thi im, ch c mt tin trnh c th nhn trng thi Running trn mt b x l bt k. Trong khi , nhiu tin trnh c th trng thi Ready hay Waiting.


Ch x l c a ti n tr nh

Ch x l ca tin trnh

  • Tp lnh ca CPU c phn chia thnh cc lnh c quyn (lnh c nguy c nh hng n h thng) v lnh khng c quyn. Phn cng ch cho php cc lnh c quyn c thc hin trong ch c quyn. Thng thng ch c H iu Hnh hot ng trong ch c quyn, cc tin trnh ca ngi dng hot ng trong ch khng c quyn, khng thc hin c cc lnh c quyn c nguy c nh hng n h thng.

  • Khi mt tin trnh ngi dng gi n mt li gi h thng, tin trnh ca H iu Hnh x l li gi ny s hot ng trong ch c quyn, sau khi hon tt th tr quyn iu khin v cho tin trnh ngi dng trong ch khng c quyn.


C u 4 qu n l ti n tr nh c u tr c d li u kh i qu n l ti n tr nh v thao t c tr n ti n tr nh

* Cu 4: Qun l tin trnh: Cu trc d liu khi qun l tin trnh v Thao tc trn tin trnh

iu Hnh qun l cc tin trnh trong h thng thng qua khi qun l tin trnh (Process Control Block PCB, cn gi l Task Control Block). PCB l mt vng nh lu tr cc thng tin m t cho mt tin trnh ch nh, vi 05 thnh phn ch yu bao gm:

  • nh danh ca tin trnh (1) gip phn bit cc tin trnh.

  • Trng thi tin trnh (2) xc nh hot ng hin hnh ca tin trnh (new, ready, running, waiting, ).

  • Ng cnh ca tin trnh (3) m t cc ti nguyn tin trnh ang s dng,. Ng cnh bao gm cc thng tin v:

    • Trng thi CPU: bao gm ni dung cc thanh ghi, quan trng nht l con tr lnh IP lu tr a ch cu lnh k tip tin trnh s x l.

    • S hiu b x l: xc nh s hiu CPU m tin trnh ang s dng.

    • B nh chnh: danh sch cc khi nh c cp cho tin trnh.

    • Ti nguyn s dng: danh sch cc ti nguyn h thng m tin trnh ang s dng.

    • Ti nguyn to lp: danh sch cc ti nguyn c tin trnh to lp.

  • Thng tin giao tip(4) phn nh cc thng tin v quan h ca tin trnh vi cc tin trnh khc trong h thng:

    • Tin trnh cha (parent): tin trnh to lp tin trnh ny.

    • Tin trnh con (progeny): cc tin trnh do tin trnh ny to lp.

    • u tin (priority): gip b iu phi c thng tin la chn tin trnh c cp CPU.

  • Thng tin thng k (5) l nhng thng tin thng k v hot ng ca tin trnh, nh thi gian s dng CPU, thi gian ch.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

RCB1

Unit1

PCB1

PCB

RCB1

Unit2

PCB2

RCB2

RCB2

PCB3

pid

status

ready queue / waiting queue

CPU-state-rec

processor

main store

resource

created resource

parent

progeny

priority

CPU time

...


5 thao t c c a h h tr n ti n tr nh

5 thao tc ca HH trn tin trnh

  • H iu Hnh cung cp cc thao tc ch yu sau y trn mt tin trnh:

    + To lp tin trnh (process creation)

    + Kt thc tin trnh (process termination)

    + Tm dng tin trnh (process suspension)

    + Ti kch hot tin trnh (resume)

    + Thay i u tin tin trnh.


C u 5 i u ph i ti n tr nh 5 m c ti u i u ph i i u ph i kh ng c quy n v i u ph i c quy n

* Cu 5: iu phi tin trnh: 5 Mc tiu iu phi. iu phi khng c quyn v iu phi c quyn.

  • B iu phi (scheduler) s s dng mt gii thut iu phi thch hp la chn tin trnh c x l tip theo. B phn phi (dispatcher) s chu trch nhim chuyn i ng cnh v trao CPU cho tin trnh c chn bi b iu phi thc thi.

  • Hng i iu phi (Scheduling Queue)

  • Cc cp iu phi

  • Chuyn i ng cnh


C c ti u chu n i u ph i

Cc tiu chun iu phi

  • S cng bng ( Fairness) :

    • Cc tin trnh chia s CPU mt cch cng bng, khng c tin trnh no phi ch i v hn c cp pht CPU

  • Tnh hiu qa (Efficiency) :

    • H thng phi tn dng c CPU 100% thi gian.

  • Thi gian p ng hp l (Response time) :

    • Cc tiu ho thi gian hi p cho cc tng tc ca ngi s dng

  • Thi gian lu li trong h thng ( Turnaround Time) :

    • Cc tiu ha thi gian hon tt cc tc v x l theo l.

  • Thng lng ti a (Throughput ) :

    • Cc i ha s cng vic c x l trong mt n v thi gian.


Hai nguy n l i u ph i

Hai nguyn l iu phi

  • H iu Hnh c th thc hin iu phi theo nguyn l

    • c quyn (u tin trc - nonpreemptive) hoc

    • khng c quyn (khng u tin trc preemptive).


I u ph i c quy n

iu phi c quyn

  • iu phi nonpreemptive:Nguyn l iu phi c quyn cho php mt tin trnh khi nhn c CPU s c quyn c chim CPU n khi hon tt x l hoc t nguyn gii phng CPU.

  • Khi quyt nh iu phi CPU s xy ra trong cc tnh hung sau:

    • Khi tin trnh chuyn t trng thi ang x l(running) sang trng thi b kha blocked ( v d ch mt thao tc nhp xut hay ch mt tin trnh con kt thc).

    • Khi tin trnh kt thc.

  • Cc gii thut c quyn thng n gin v d ci t. Tuy nhin chng thng khng thch hp vi cc h thng tng qut nhiu ngi dng, v nu cho php mt tin trnh c quyn x l bao lu ty , c ngha l tin trnh ny c th gi CPU mt thi gian khng xc nh, c th ngn cn nhng tin trnh cn li trong h thng c mt c hi x l.


I u ph i kh ng u ti n tr c

iu phi khng u tin trc

  • iu phi preemptive: Ngc vi nguyn l c quyn, iu phi theo nguyn l khng c quyn cho php tm dng hot ng ca mt tin trnh ang sn sng x l. Nh vy l tin trnh c th b tm dng hot ng bt c lc no m khng c bo trc, tin trnh khc x l. Cc quyt nh iu phi xy ra khi:

    • Khi tin trnh chuyn t trng thi ang x l (running) sang trng thi b kha blocked ( v d ch mt thao tc nhp xut hay ch mt tin trnh con kt thc).

    • Khi tin trnh chuyn t trng thi ang x l (running) sang trng thi ready ( v d xy ra mt ngt).

    • Khi tin trnh chuyn t trng thi ch (blocked) sang trng thi ready ( v d mt thao tc nhp/xut hon tt).

    • Khi tin trnh kt thc.

  • Cc thut ton iu phi theo nguyn tc khng c quyn ngn cn c tnh trng mt tin trnh c chim CPU, nhng vic tm dng mt tin trnh c th dn n cc mu thun trong truy xut, i hi phi s dng mt phng php ng b ha thch hp gii quyt.


C u 6 t ch c i u ph i ti n tr nh chi n l c fifo xoay v ng round robin

*Cu 6: T chc iu phi tin trnh: Chin lc FIFO, xoay vng (Round Robin),

  • Gii thut First-Come First-Served (FCFS n trc, phc v trc)

  • Gii thut n gin nht. Cc tin trnh c iu phi theo th t trong Ready Queue, tin trnh no yu cu trc s c phn phi CPU trc. y l thut ton iu phi nonpreemptive, cn gi l FIFO.

Ready Queue

P1

P3

P2

CPU


V d fifo

V d FIFO

Th t cp pht CPU cho cc tin trnh l:

thi gian ch i c x l l 0 i vi P1, (24 -1) vi P2 v (24+3-2) vi P3. Thi gian ch trung bnh l

(0+23+25)/3 = 16 milisecondes.


Chi n l c ph n ph i xoay v ng round robin

Chin lc phn phi xoay vng (Round Robin)

  • Danh sch sn sng c x l nh mt danh sch vng, b iu phi ln lt cp pht cho tng tin trnh trong danh sch mt khong thi gian s dng CPU gi l quantum.

  • y l mt gii thut iu phi khng c quyn: khi mt tin trnh s dng CPU n ht thi gian quantum dnh cho n, h iu hnh thu hi CPU v cp cho tin trnh k tip trong danh sch.

  • Nu tin trnh b kha hay kt thc trc khi s dng ht thi gian quantum, h iu hnh cng lp tc cp pht CPU cho tin trnh khc.

  • Khi tin trnh s dng ht thi gian CPU dnh cho n m cha hon tt, tin trnh c a tr li vo cui danh sch sn sng i c cp CPU trong lt k tip.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

* Cu 7:T chc iu phi tin trnh: iu phi c u tin, cng vic ngn nht (Shortest-job-first SJF) v iu phi vi nhiu mc u tin

iuphiviutin

  • Mitintrnhcgnchomtutintngng, tintrnhcutincaonhtscchncppht CPU utin.

  • utincthcnhnghaniti hay nhvoccyutbnngoi.

    • utinnitisdngccilngctholngtnhtonutincatintrnh, vdccgiihnthigian, nhucubnh

    • utincngcthcgntbnngoidavocctiuchun do hiuhnhnhtmquantrngcatintrnh, loingisdngshutintrnh


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

S dng thut gii c quyn, th t cp pht CPU nh sau:

Thi gian ch?

S dng thut gii khng c quyn, th t cp pht CPU nh sau:

Thi gian ch?


Chi n l c c ng vi c ng n nh t shortest job first sjf

Chin lc cng vic ngn nht (Shortest-job-first SJF)

  • y l mt trng hp c bit ca gii thut iu phi vi u tin.

  • u tin p c gn cho mi tin trnh l nghch o ca thi gian x l t m tin trnh yu cu: p = 1/t.

  • Khi CPU c t do, n s c cp pht cho tin trnh yu cu t thi gian nht kt thc- tin trnh ngn nht.

  • Gii thut ny cng c th c quyn hay khng c quyn.

  • Tin trnh mi c th s hu mt yu cu thi gian s dng CPU cho ln tip theo (CPU-burst) ngn hn thi gian cn li m tin trnh hin hnh cn x l.

  • Gii thut SJF khng c quyn s dng hot ng ca tin trnh hin hnh, trong khi gii thut c quyn s cho php tin trnh hin hnh tip tc x l.


C u 8 li n l c gi a c c ti n tr nh c c c ch li n l c

* Cu 8: Lin lc gia cc tin trnh: Cc c ch lin lc

Tn hiu (Signal)

Tn hiu l mt c ch phn mm tng t nh cc ngt cng tc ng n cc tin trnh. Mt tn hiu c s dng thng bo cho tin trnh v mt s kin no xy ra. C nhiu tn hiu c nh ngha, mi mt tn hiu c mt ngha tng ng vi mt s kin c trng.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

Mt s tn hiu ca UNIX


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

  • Cc tn hiu c gi i bi

    • Phn cng (v d li do cc php tnh s hc)

    • Ht nhn h iu hnh gi n mt tin trnh ( v d lu tin trnh khi c mt thit b nhp/xut t do).

    • Mt tin trnh gi n mt tin trnh khc ( v d tin trnh cha yu cu mt tin trnh con kt thc)

    • Ngi dng ( v d nhn phm Ctl-C ngt x l ca tin trnh)

  • Khi mt tin trnh nhn mt tn hiu, n c th x s theo mt trong cc cch sau:

    • B qua tn hiu

    • X l tn hiu theo kiu mc nh

    • Tip nhn tn hiu v x l theo cch c bit ca tin trnh.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

Pipe

  • Mt pipe l mt knh lin lc trc tip gia hai tin trnh: d liu xut ca tin trnh ny c chuyn n lm d liu nhp cho tin trnh kia di dng mt dng cc byte.

  • Khi mt pipe c thit lp gia hai tin trnh, mt trong chng s ghi d liu vo pipe v tin trnh kia s c d liu t pipe. Th t d liu truyn qua pipe c bo ton theo nguyn tc FIFO.

  • Mt pipe c kch thc gii hn (thng l 4096 k t)


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

  • Mt tin trnh ch c th s dng mt pipe do n to ra hay k tha t tin trnh cha. H iu hnh cung cp cc li gi h thng read/write cho cc tin trnh thc hin thao tc c/ghi d liu trong pipe. H iu hnh cng chu trch nhim ng b ha vic truy xut pipe trong cc tnh hung:

    • Tin trnh c pipe s b kha nu pipe trng, n s phi i n khi pipe c d liu truy xut.

    • Tin trnh ghi pipe s b kha nu pipe y, n s phi i n khi pipe c ch trng cha d liu

  • C ch ny cho php truyn d liu vi cch thc khng cu trc.

  • Ngoi ra, mt gii hn ca hnh thc lin lc ny l ch cho php kt ni hai tin trnh c quan h cha-con, v trn cng mt my tnh.


V ng nh chia s

Vng nh chia s

  • Cch tip cn ca c ch ny l cho nhiu tin trnh cng truy xut n mt vng nh chung gi l vng nh chia s(shared memory).Khng c bt k hnh vi truyn d liu no cn phi thc hin y, d liu ch n gin c t vo mt vng nh m nhiu tin trnh c th cng truy cp c.

  • Vi phng thc ny, cc tin trnh chia s mt vng nh vt l thng qua trung gian khng gian a ch ca chng. Mt vng nh chia s tn ti c lp vi cc tin trnh, v khi mt tin trnh mun truy xut n vng nh ny, tin trnh phi kt gn vng nh chung vo khng gian a ch ring ca tng tin trnh, v thao tc trn nh mt vng nh ring ca mnh


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

  • y l phng php nhanh nht trao i d liu gia cc tin trnh. Nhng phng thc ny cng lm pht sinh cc kh khn trong vic bo m s ton vn d liu (coherence) , v d: lm sao bit c d liu m mt tin trnh truy xut l d liu mi nht m tin trnh khc ghi? Lm th no ngn cn hai tin trnh cng ng thighi d liu vo vng nh chung

  • Mt khuyt im ca phng php lin lc ny l khng th p dng hiu qu trong cc h phn tn , trao i thng tin gia cc my tnh khc nhau.


Sockets

Sockets

  • Mt socket l mt thit b truyn thng hai chiu tng t nh tp tin, chng ta c th c hay ghi ln n, tuy nhin mi socket l mt thnh phn trong mt mi ni no gia cc my trn mng my tnh v cc thao tc c/ghi chnh l s trao i d liu gia cc ng dng trn nhiu my khc nhau.

  • S dng socket c th m phng hai phng thc lin lc trong thc t: lin lc th tn (socket ng vai tr bu cc) v lin lc in thoi (socket ng vai tr tng i) .


C c thao t c li n l c b ng socket

Cc thao tc lin lc bng socket

  • To lp hay m mt socket

  • Gn kt mt socket vi mt a ch

  • Lin lc : c hai kiu lin lc ty thuc vo ch ni kt:

    • Lin lc trong ch khng lin kt : lin lc theo hnh thc hp th

    • Lin lc trong ch ni kt:

  • Hy mt socket


C u 9 ng b h a synchronisation y u c u c quy n truy xu t y u c u ph i h p

*Cu 9: ng b ha (synchronisation): Yu cu c quyn truy xut, Yu cu phi hp

Yucucquyntruyxut (Mutual exclusion)

  • Cctinguyntronghthngcphnthnhhailoi: tinguyncth chia schophpnhiutintrnhngthitruyxut, vtinguynkhngth chia schchpnhnmt ( hay mtslnghnch ) tintrnhsdngtimtthiim.

  • Tnhkhngth chia scatinguynthngcngungctmttronghainguynnhnsauy:

    • ctnhcutophncngcatinguynkhngchophp chia s.

    • Nunhiutintrnhsdngtinguynngthi, cnguycxyraccktqukhngdonc do hotngcacctintrnhtrntinguynnhhnglnnhau.

  • giiquytvn, cnbomtintrnhcquyntruyxuttinguyn, nghalhthngphikimsotsaochotimtthiim, chcmttintrnhcquyntruyxutmttinguynkhngth chia s.


Y u c u ph i h p synchronization

Yu cu phi hp (Synchronization)

  • Nhn chung, mi tng quan v tc thc hin ca hai tin trnh trong h thng l khng th bit trc, v iu ny ph thuc vo nhiu yu t ng nh tn sut xy ra cc ngt ca tng tin trnh, thi gian tin trnh c cp pht b x l

  • C th ni rng cc tin trnh hot ng khng ng b vi nhau. Nhng c nhng tnh hung cc tin trnh cn hp tc trong vic hon thnh tc v, khi cn phi ng b ha hot ng ca cc tin trnh , v d mt tin trnh ch c th x l nu mt tin trnh khc kt thc mt cng vic no


C u 10 b i to n ng b ho tranh i u khi n v mi n g ng

Cu 10: Bi ton ng b ho: tranh iu khin v min gng

Vn tranh ot iu khin (race condition)

  • Gi s c hai tin trnh P1 v P2 thc hin cng vic ca cc k ton, v cng chia s mt vng nh chung lu tr bin taikhoan phn nh thng tin v ti khon. Mi tin trnh mun rt mt khon tin tienrut t ti khon:

    if (taikhoan - tienrut >=0)

    taikhoan = taikhoan - tienrut;

    else

    error(khong the rut tien!);


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

  • Gi s trong ti khon hin cn 800, P1 mun rt 500 v P2 mun rt 400. Nu xy ra tnh hung nh sau:

    • Sau khi kim tra iu kin (taikhoan - tienrut >=0) v nhn kt qu l 300, P1 ht thi gian x l m h thng cho php, h iu hnh cp pht CPU cho P2.

    • P2 kim tra cng iu kin trn, nhn c kt qu l 400 (do P1 vn cha rt tin) v rt 400. Gi tr ca taikhoan c cp nht li l 400.

    • Khi P1 c ti kch hot v tip tc x l, n s khng kim tra li iu kin (taikhoan - tienrut >=0)-v kim tra trong lt x l trc- m thc hin rt tin. Gi tr ca taikhoan s li c cp nht thnh -100. Tnh hung li xy ra!


Mi n g ng critical section

Min gng (critical section)

on chng trnh trong c kh nng xy ra cc mu thun truy xut trn ti nguyn chung c gi l min gng (critical section). Trong v d trn, on m:

if (taikhoan - tienrut >=0)

taikhoan = taikhoan - tienrut;

ca mi tin trnh to thnh mt min gng.

  • C th gii quyt vn mu thun truy xut nu c th bo m ti mt thi im ch c duy nht mt tin trnh c x l lnh trong min gng.


Mi n g ng critical section1

Min gng (critical section)

  • Mt phng php gii quyt tt bi ton min gng cn tha mn 4 iu kin sau:

    • Khng c hai tin trnh cng trong min gng cng lc.

    • Khng c gi thit no t ra cho s lin h v tc ca cc tin trnh, cng nh v s lng b x l trong h thng.

    • Mt tin trnh tm dng bn ngoi min gng khng c ngn cn cc tin trnh khc vo min gng.

    • Khng c tin trnh no phi ch v hn c vo min gng.


C u 11 gi i ph p ng b h a gi i ph p c hi u

* Cu 11: Gii php ng b ha: Gii php c hiu

Giiphp busy waiting

  • Ccgiiphpphnmm

    Sdngccbinchiu (chtca)

  • Cctintrnh chia smtbinchungngvaitr chtca (lock) , binnyckhingl 0.

  • Mttintrnhmunvomingngtrctinphikimtragitrcabin lock.

    • Nu lock = 0, tintrnhtligitrcho lock = 1 vivomingng.

    • Nu lock angnhngitr 1, tintrnhphichbnngoimingngchonkhi lock cgitr 0.

  • Nhvygitr 0 ca lock mang nghalkhngctintrnhnoang trongmingng, v lock=1 khicmttintrnhang trongmingng.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

while (TRUE) {

while (lock == 1); // waitlock = 1; critical-section ();lock = 0;Noncritical-section ();

}

Vn b vi phm : hai tin trnh cng vo min gng !


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

* Cu 12: Giiphpngbha: Giiphpkimtralunphin

  • Sdngvickimtralunphin :

    ylmtgiiphpnghchohaitintrnh. Haitintrnhnysdngchungbinturn (phnnhphintintrnhnocvomingng), ckhingvigitr 0. Nuturn = 0, tintrnh A cvomingng. Nuturn = 1,tintrnh A ivomtvnglpchnkhiturnnhngitr0. Khitintrnh A rikhimingng, ntgitrturn v 1 chophptintrnh B ivomingng.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

while (TRUE) {

while (turn!= 0); // waitcritical-section ();turn = 1;Noncritical-section ();

}

Cu trc tin trnh A

while (TRUE) {

while (turn!= 1); // waitcritical-section ();turn = 0;Noncritical-section ();

}

Cu trc tin trnh B

Vn b li!


C u 13 gi i ph p ng b h a gi i ph p c a peterson

Cu 13: Gii php ng b ha: Gii php ca Peterson

Petson a ra mt gii php kt hp tng ca c hai gii php k trn. Cc tin trnh chia s hai bin chung :

int turn; // n phin ai

int interesse[2]; // khi ng l FALSE

Nu interesse[i] = TRUE c ngha l tin trnh Pi mun vo min gng.

Khi u, interesse[0]=interesse[1]=FALSE v gi tr ca turn c khi ng l 0 hay 1.

c th vo c min gng, trc tin tin trnh Pi t gi tr interesse[i]=TRUE ( xc nh rng tin trnh mun vo min gng), sau t turn=j ( ngh th tin trnh khc vo min gng).

Nu tin trnh Pj khng quan tm n vic vo min gng (interesse[j]=FALSE), th Pi c th vo min gng, nu khng, Pi phi ch n khi interesse[j]=FALSE. Khi tin trnh Pi ri khi min gng, n t li gi tr cho interesse[i]= FALSE.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

while (TRUE) {

int j = 1-i; // j l tin trnh cn liinteresse[i]= TRUE;turn = j;while (turn== j && interesse[j]==TRUE);critical_section ();interesse[i] = FALSE;Noncritical-section ();

}


C u 14 gi i ph p ph n c ng c m ng t tsl

* Cu 14: Gii php phn cng: Cm ngt, TSL

Ccgiiphpphncng

  • Cmngt:

    Cho phptintrnhcmttcccngttrckhivomingng, vphchingtkhirakhimingng.

    Khi, ngtnghcngkhngxyra, do vyhthngkhngthtmdnghotngcatintrnhangxlcppht CPU chotintrnhkhc, nhtintrnhhinhnhyntmthaotctrnmingngmkhngsbtintrnhnokhctranhchp.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

  • Ch th TSL (Test-and-Set):

  • y l mt gii php i hi s tr gip ca c ch phn cng.

  • Nhiu my tnh cung cp mt ch th c bit cho php kim tra v cp nht ni dung mt vng nh trong mt thao tc khng th phn chia, gi l ch th Test-and-Set Lock (TSL) v c nh ngha nh sau


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

Test-and-Setlock(boolean target){

Test-and-Setlock = target;target = TRUE;

}


C u17 qu n l b nh a ch v t l v a ch logic

*Cu17: Qun l b nh : a ch vt l v a ch logic

Tngquan

  • Bnhchnhlthitblutrduynhtthng qua CPU cthtraoithng tin vimitrngngoi, do vynhucutchc, qunlbnhlmttrongnhngnhimvtrngtmhngucahiuhnh .

  • Bnhchnhctchcnhmtmngmtchiucctnh (word), mitnhcmtach .

  • Victraoithng tin vimitrngngoicthchinthng qua ccthaotc

    • choc

    • ghidliu.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

  • S tng ng gia a ch logic v a ch vt l (physic):lm cch no chuyn i mt a ch tng trng (symbolic) trong chng trnh thnh mt a ch thc trong b nh chnh?

  • Qun l b nh vt l: lm cch no m rng b nh c sn nhm lu tr c nhiu tin trnh ng thi?

  • Chia s thng tin: lm th no cho php hai tin trnh c th chia s thng tin trong b nh?

  • Bo v: lm th no ngn chn cc tin trnh xm phm n vng nh c cp pht cho tin trnh khc?


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

C th thc hin kt buc cc ch th v d liu vi cc a ch b nh vo mt trong nhng thi im sau:

  • Thi im bin dch.

  • Thi im np.

  • Thi im x l.


C u 18 c p ph t b nh li n t c

* Cu 18: Cp pht b nh lin tc

Cpphtlintc

  • MhnhLinker_Loader

    • Tintrnhcnpvomtvngnhlintclnchatonbtintrnh.

    • Tithiimbindchccachbntrongtintrnhvnlachtngi.

    • Tithiimnp, Hiuhnhstrvachbtunptintrnh, vtnhtonchuynccachtngivachtuytitrongbnhvtltheocngthcachvtl = achbtu + achtngi.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

  • Thi im kt buc a ch l thi im np, do vy sau khi np khng th di chuyn tin trnh trong b nh .

  • Khng c kh nng kim sot a ch cc tin trnh truy cp, do vy khng c s bo v


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

  • M hnh Base &Bound

  • Tin trnh c np vo mt vng nh lin tc ln cha ton b tin trnh.

  • Ti thi im bin dch cc a ch bn trong tin trnh vn l a ch tng i.

  • Tuy nhin b tc vo cu trc phn cng ca my tnh mt thanh ghi nn (base register) v mt thanh ghi gii hn (bound register).

  • Khi mt tin trnh c cp pht vng nh, np vo thanh ghi nn a ch bt u ca phn vng c cp pht cho tin trnh, v np vo thanh ghi gii hn kch thc ca tin trnh.

  • Sau , mi a ch b nh c pht sinh s t ng c cng vi a ch cha trong thanh ghi nn cho ra a ch tuyt i trong b nh, cc a ch cng c i chiu vi thanh ghi gii hn bo m tin trnh khng truy xut ngoi phm vi phn vng c cp cho n.


C u 19 c p ph t b nh ph n o n segmentation

* Cu 19: Cp pht b nh Phn on (Segmentation)

Cpphtkhnglintc

  • Phnon (Segmentation)

  • khnggianachlmttpccphnon (segments) ccphnonlnhngphnbnhkchthckhcnhauvclinh logic vinhau.

  • Miphnoncmttngi (shiuphnon) vmtdi. Ngidngsthitlpmiachvihaigitr: <shiuphnon, offset>.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

stack

ngn xp

symbol table

bng k hiu

subroutine

chng trnh con

main program

chng trnh chnh

khng gian

vt l

khng gian a ch


C ch mmu trong k thu t ph n o n

C ch MMU trong k thut phn on

  • Cn phi xy dng mt nh x chuyn i cc a ch 2 chiu c ngi dng nh ngha thnh a ch vt l mt chiu.

  • S chuyn i ny c thc hin qua mt bng phn on.

  • Mi thnh phn trong bng phn on bao gm mt thanh ghi nn v mt thanh ghi gii hn.

  • Thanh ghi nn lu tr a ch vt l ni bt u phn on trong b nh,

  • Thanh ghi gii hn c t chiu di ca phn on


Chuy n i a ch

Chuyn i a ch

  • Mi a ch o l mt b <s,d>:

  • s hiu phn on s : c s dng nh ch mc n bng phn on

  • a ch tng i d : c gi tr trong khong t 0 n gii hn chiu di ca phn on. Nu a ch tng i hp l, n s c cng vi gi tr cha trong thanh ghi nn pht sinh a ch vt l tng ng


C i t b ng ph n o n

Ci t bng phn on

  • C th s dng cc thanh ghi lu tr bng phn on nu s lng phn on nh. Trong trng hp chng trnh bao gm qu nhiu phn on, bng phn on phi c lu trong b nh chnh.

  • Mt thanh ghi nn bng phn on (STBR) ch n a ch bt u ca bng phn on. V s lng phn on s dng trong mt chng trnh bin ng, cn s dng thm mt thanh ghi c t kch thc bng phn on (STLR)


C u 20 c p ph t b nh ph n trang paging

* Cu 20: Cp pht b nh Phn trang ( Paging)

Phntrang ( Paging)

  • Phnbnhvtlthnhcckhi (block) ckchthccnhvbngnhau, gilkhungtrang (page frame).

  • Khnggianachcngc chia thnhcckhiccngkchthcvikhungtrang, vcgiltrang(page).

  • Khicnnpmttintrnhxl, cctrangcatintrnhscnpvonhngkhungtrangcntrng.

  • Mttintrnhkchthc N trangsyucu N khungtrangt do.


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

segment length

page-table base

a ch logic

s

d

yes

+

STBR

d

no

trap

s

d

bng phn on

+

B nh

f

d

f

a ch vt l

bng trang cho segment s


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

segment length

page-table base

a ch logic

s

d

yes

+

STBR

d

no

trap

s

d

bng phn on

+

B nh

f

d

f

a ch vt l

bng trang cho segment s


C u 22 b nh o ph n trang theo y u c u

Cu 22: B nh o: Phn trang theo yu cu

nhngha

  • Bnholmtkthutchophpxlmttintrnhkhngcnptonbvobnhvtl.

  • Bnhomhnhhobnhnhmtbnglutrrtlnvngnht, tchbithnkhinimkhnggianachvkhnggianvtl.


L i trang

Li trang

  • Truy xut n mt trang c nh du bt hp l s lm pht sinh mt li trang (page fault). Khi d tm trong bng trang ly cc thng tin cn thit cho vic chuyn i a ch, nu nhn thy trang ang c yu cu truy xut l bt hp l, c ch phn cng s pht sinh mt ngt bo cho h iu hnh.


X l l i trang

X l li trang

Kim tra truy xut n b nh l hp l hay bt hp l (1)

Nu truy xut bt hp l: kt thc tin trnh

Ngc li: n bc (3) Xc nh v tr trn a

Tm v tr cha trang mun truy xut trn a. (4)

Tm mt khung trang trng trong b nh chnh :

Nu tm thy: n bc 5

Nu khng cn khung trang trng, chn mt khung trang nn nhn v chuyn trang nn nhn ra b nh ph (lu ni dung ca trang ang chim gi khung trang ny ln a) (bc 3), cp nht bng trang tng ng ri n bc 5

Chuyn trang mun truy xut t b nh ph vo b nh chnh: np trang cn truy xut vo khung trang trng chn (hay va mi lm trng ); cp nht ni dung bng trang, bng khung trang tng ng.

Ti kch hot tin trnh ngi s dng (6).


C u h i n t p

Cu hi n tp

1. Chc nng, nhim v ca h iu hnh. Phn loi h iu hnh

2. Tin trnh (process) v tiu trnh (thread): Nguyn l chung, thng tin lu tr v phn loi tiu trnh

3. Qun l tin trnh: Cc trng thi v ch x l tin trnh

4. Qun l tin trnh: Cu trc d liu khi qun l tin trnh v Thao tc trn tin trnh

5. iu phi tin trnh: 5 Mc tiu iu phi. iu phi khng c quyn v iu phi c quyn.

6. T chc iu phi tin trnh: Chin lc FIFO, xoay vng (Round Robin),

7. T chc iu phi tin trnh: iu phi c u tin, cng vic ngn nht (Shortest-job-first SJF) v iu phi vi nhiu mc u tin

8. Lin lc gia cc tin trnh: Cc c ch lin lc

9. ng b ha (synchronisation): Yu cu c quyn truy xut, Yu cu phi hp

10. Bi ton ng b ho: tranh iu khin v min gng


C u 1 ch c n ng nhi m v c a h i u h nh ph n lo i h i u h nh

11. Gii php ng b ha: Gii php c hiu

12. Gii php ng b ha: Gii php kim tra lun phin

13. Gii php ng b ha: Gii php Gii php ca Peterson

14. Gii php phn cng: Cm ngt, TSL

15. ng b bng Semaphores

16. ng b bng Monitors

17. Qun l b nh : a ch vt l v a ch logic

18. Cp pht b nh lin tc

19. Cp pht b nh Phn on (Segmentation)

20. Cp pht b nh Phn trang ( Paging)

21. Cp pht b nh Phn on kt hp phn trang (Paged segmentation)

22. B nh o: Phn trang theo yu cu


  • Login