Bài giảng Hệ điều hành: Chương 2 - Thoại Nam, Lê Ngọc Minh

pdf
Số trang Bài giảng Hệ điều hành: Chương 2 - Thoại Nam, Lê Ngọc Minh 34 Cỡ tệp Bài giảng Hệ điều hành: Chương 2 - Thoại Nam, Lê Ngọc Minh 758 KB Lượt tải Bài giảng Hệ điều hành: Chương 2 - Thoại Nam, Lê Ngọc Minh 0 Lượt đọc Bài giảng Hệ điều hành: Chương 2 - Thoại Nam, Lê Ngọc Minh 12
Đánh giá Bài giảng Hệ điều hành: Chương 2 - Thoại Nam, Lê Ngọc Minh
4.9 ( 21 lượt)
Nhấn vào bên dưới để tải tài liệu
Đang xem trước 10 trên tổng 34 trang, để tải xuống xem đầy đủ hãy nhấn vào bên trên
Chủ đề liên quan

Nội dung

Chöông 2 KHAÙI NIEÄM VEÀ QUAÙ TRÌNH -4.1- Noäi dung ‰ ‰ ‰ ‰ ‰ ‰ Khaùi nieäm cô baûn Ñònh thôøi process (CPU scheduling) Caùc taùc vuï treân process (taïo process, keát thuùc process) Söï coäng taùc giöõa caùc process Interprocess Communication (IPC) Moâ hình giao tieáp Client-Server Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.2- https://fb.com/tailieudientucntt 1 Khaùi nieäm cô baûn ‰ OS thöïc thi nhieàu chöông trình khaùc nhau – Batch system: jobs – Time-shared systems: user programs, tasks – Job ≈ process ‰ Process – moät chöông trình ñang thöïc thi (executing program). ‰ Moät process bao goàm caùc phaàn – Text section(program code), data section(global variable), stack (local variable,…) – Hardware: Program Counter(PC), Process Status Word (PSW), Stack Pointer (SP), Memory Management Registers ‰ So saùnh process vaø program – Process = active <> passive = programing Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.3- Process Control Block (PCB) ‰ Chöùa caùc thoâng tin öùng vôùi moãi process. – – – – – – – – – Process ID, parent process ID Credentials (user ID, group ID, effective ID,...) Traïng thaùi process : new, ready, running, waiting… Program counter: ñòa chæ cuûa leänh keá tieáp seõ thöïc thi Caùc thanh ghi CPU Thoâng tin duøng ñeå ñònh thôøi CPU: priority,... Thoâng tin boä nhôù: base/limit register, page tables… Thoâng tin thoáng keâ: CPU time, time limits… Thoâng tin traïng thaùi I/O: danh saùch thieát bò I/O ñöôïc caáp phaùt, danh saùch caùc file ñang môû,... – Con troû (pointer) ñeán PCBs khaùc. Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.4- https://fb.com/tailieudientucntt 2 Process Control Block (PCB) Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.5- User Processes in Virtual Memory Process Identification Process Identification Process Identification Process State Inform ation Process State Inform ation Process State Inform ation Process C ontrol Inform ation Process C ontrol Inform ation Process C ontrol Inform ation U serStack U serStack U serStack Private U ser Private U ser Address Space Address Space (Program s,D ata) (Program s,D ata) (Program s,D ata) Shared Address Space Shared Address Space Shared Address Space Process 1 Process 2 Process n Private U ser … Address Space Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com Process C ontrol Block -4.6- https://fb.com/tailieudientucntt 3 Caùc böôùc naïp process vaøo boä nhôù ‰ ‰ Linker: keát hôïp caùc object modules thaønh moät file nhò phaân coù theå thöïc thi (executable binary file) goïi laø load module Loader: naïp load module vaøo boä nhôù chính Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.7- Loader Process C ontrolB lock Program C ode Program C ode D ata D ata Executable Binary File (Load M odule) Stack ™ Program Æ Process Process Im age in M ain M em ory Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.8- https://fb.com/tailieudientucntt 4 Yeâu caàu ñoái vôùi OS ‰ ‰ ‰ ‰ OS phaûi hoã trôï söï thöïc thi luaân phieân giöõa nhieàu process ñeå toái öu hieäu suaát CPU vôùi moät thôøi gian ñaùp öùng coù theå chaáp nhaän ñöôïc (reasonable response time) → ñònh thôøi CPU OS phaûi phaân phoái taøi nguyeân heä thoáng (resources) cho processes (boä nhôù, thieát bò I/O,...) ñoàng thôøi phaûi traùnh hieän töôïng deadlock OS phaûi cung caáp cô cheá giao tieáp giöõa caùc process khaùc nhau (inter-process communication), cô cheá ñoàng boä hoaït ñoäng caùc process (synchronization) OS phaûi cung caáp cô cheá hoã trôï cho user taïo vaø huûy caùc process. Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.9- Caùc traïng thaùi cuûa process ‰ Khi thöïc thi, process chuyeån töø traïng thaùi naøy sang traïng thaùi khaùc, bao goàm – New: process môùi vöøa ñöôïc taïo ra (ñöôïc boû vaøo job queue) – Ready: process chôø ñöôïc chieám CPU ñeå laøm vieäc (ñöôïc xeáp vaøo ready queue) – Running: caùc leänh cuûa process ñang ñöôïc thöïc hieän. – Waiting: process chôø moät söï kieän naøo ñoù xaûy ra, ví duï moät thao taùc I/O vöøa hoaøn taát,... (xeáp vaøo waiting queue) – Terminated: söï thöïc thi cuûa process keát thuùc Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.10- https://fb.com/tailieudientucntt 5 Löu ñoà 5-traïng thaùi process dispatch adm it new exit ready term inated running interrupt I/O or eventw ait I/O orevent com pletion blocked ™ Chæ coù moät process ôû traïng thaùi running treân moãi processor taïi moät thôøi ñieåm ™ Coù theå coù nhieàu process ôû traïnh thaùi ready vaø waiting Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.11- Ví duï veà traïng thaùi process test.c ‰ void main() { printf(“Hello World\n"); } Bieân dòch trong Linux/Unix $ gcc test.c –o test Thöïc thi chöông trình test $ ./test Chuoãi traïng thaùi cuûa process test nhö sau: – – – – – – – new ready running blocked (chôø I/O) ready running terminated Trong heä thoáng seõ coù moät process test ñöôïc taïo ra, thöïc thi vaø keát thuùc. Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.12- https://fb.com/tailieudientucntt 6 Caùc traïng thaùi cuûa process (t.t) ‰ Traïng thaùi New – OS thöïc hieän caùc taùc vuï caàn thieát ñeå taïo process » Taïo moät ñònh danh cho process (process identifier – pid) » Taïo caùc caáu truùc ñeå quaûn lyù process – Memory table, file table, Process Control Block (PCB),... – Process môùi taïo ra coù theå chöa ñöôïc thöïc thi ngay, bôûi vì taøi nguyeân heä thoáng coù haïn, thoâng thöôøng chæ phuïc vuï moät process taïi moät thôøi ñieåm. Process coù theå ñaët trong boä nhôù thöù caáp ñeå tieát kieäm khoâng gian boä nhôù chính ‰ Traïng thaùi Terminated – Process khoâng coøn ñöôïc thöïc thi nöõa – Process vaø caùc caáu truùc quaûn lyù process khoâng caàn thieát seõ bò xoùa. Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.13- Caùc traïng thaùi cuûa process (t.t) ‰ ‰ ‰ ‰ Neáu process ñang trong traïng thaùi ready hay running vaø bò suspend, noù seõ rôi vaøo traïng thaùi suspended ready Neáu process ñang trong traïng thaùi blocked vaø bò suspend, noù seõ rôi vaøo traïng thaùi suspended blocked Traïng thaùi suspend coù theå thay ñoåi neáu users hoaëc OS thöïc hieän taùc vuï resume. Process coù theå chuyeån töø traïng thaùi suspended blocked sang suspended ready neáu coù söï kieän I/O töông öùng laøm cho quaù trình ñoù bò blocked xaûy ra. Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.14- https://fb.com/tailieudientucntt 7 Caùc traïng thaùi cuûa process (t.t) ‰ ‰ Process bò suspend trong caùc tröôøng hôïp sau – User muoán taïm döøng quaù trình thöïc thi cuûa process ñeå xem keát quaû thöïc hieän, phaùt hieän loãi,… – Ngöôøi quaûn trò heä thoáng coù theå suspend moät soá process ñeå thu hoài moät soá taøi nguyeân vaø OS coù theå caáp phaùt cho process khaùc nhaèm giaûm tình traïng quaù taûi trong heä thoáng – Tröôøng hôïp coù tranh chaáp taøi nguyeân giöõa caùc process, suspend coù theå giuùp heä thoáng thoaùt khoûi tình traïng deadlock (tham khaûo theâm phaàn Deadlock) Khi rôi vaøo traïng thaùi suspend, process ñöôïc swap ra heä thoáng löu tröõ thöù caáp, nhöôøng choã trong boä nhôù cho process khaùc. Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.15- Löu ñoà 7-traïng thaùi cuûa process new adm it exit term inated dispatch ready running tim e-out event w ait event occur resum e suspend blocked suspend suspend resum e suspended ready event occur suspended blocked Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.16- https://fb.com/tailieudientucntt 8 Traïng thaùi process trong Unix fork() created preem pted enough m em ory return to user notenough m em ory preem pt user running return reschedule ready to run sw ap out sw ap in system call, interrupt kernel running interrupt, interruptreturn exit w ake-up sw apped ready w ake-up sleep asleep sw ap out sw apped sleep zoom bie Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.17- Traïng thaùi Unix process (t.t) ‰ ‰ ‰ ‰ ‰ ‰ ‰ User Running: process thöïc thi ôû user-mode Kernel Running: process thöïc thi ôû kernel-mode Ready To Run (in memory): trong haøng ñôïi ready Pre-empted: haøng ñôïi ready ñaëc bieät, process töø kernelmode veà user-mode nhöng bò OS ñoaït quyeàn (preempt), thöïc hieän chuyeån ngöõ caûnh vaø chuyeån quyeàn ñieàu khieån cho process khaùc. Asleep (in Memory): traïng thaùi blocked, chôø söï kieän (event) hoaëc taùc vuï I/O Swapped-Ready: process saün saøng nhöng caàn phaûi naïp process töø boä nhôù thöù caáp. Swapped-Sleep: Ñang ñôïi (blocked) thì bò swap out ra boä nhôù thöù caáp, nhöôøng boä nhôù chính cho process khaùc. Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.18- https://fb.com/tailieudientucntt 9 Ñònh thôøi Process – Muïc tieâu ‰ Multiprogramming – Coù nhieàu process phaûi thöïc thi luaân phieân nhau – Cöïc ñaïi hieäu suaát cuûa CPU ‰ Time Sharing – Cho pheùp users töông taùc khi chöông trình ñang chaïy – Toái thieåu thôøi gian ñaùp öùng Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM -4.19- Caùc haøng ñôïi ñònh thôøi (queue) ‰ ‰ ‰ ‰ ‰ Job queue (New): chöùa caùc process môùi ñöôïc taïo ra trong heä thoáng Ready queue (Ready): chöùa caùc process ñang naèm trong boä nhôù chính saün saøng ñôïi ñöôïc thöïc thi Device queues (Waiting): chöùa caùc process ñang chôø moät thieát bò I/O, moät söï kieän I/O Process ñöôïc chuyeån töø haøng ñôïi naøy sang haøng ñôï khaùc trong suoát quaù trình thöïc thi cuûa noù Caùc haøng ñôïi ñònh thôøi ñöôïc hieän thöïc baèng danh saùch lieân keát (linked list) – Caùc lieân keát laø caùc con troû trong khoái PCB Khoa Coâng Ngheä Thoâng Tin – Ñaïi Hoïc Baùch Khoa Tp.HCM CuuDuongThanCong.com -4.20- https://fb.com/tailieudientucntt 10
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.