OS resource management and processes
แนะนำใหม่
13:59
ทรัพยากร คอมไพเลอร์ และ RPN
เปิดเบราว์เซอร์Playersเพลง และเกม คุณมีโปรเซสเซอร์เพียงตัวเดียว — หรือบางทีก็หลายคอร์ — แต่ทั้งหมดดูเหมือนจะทำงานพร้อมกัน และทั้งหมดต้องการมากกว่านั้น…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| mouse pointer | A symbol on the screen that shows where the mouse is pointing. |
| operating system/ˈɒpəreɪtɪŋ ˈsɪstəm/ | System software that manages hardware resources and provides services for applications. |
| process/ˈprəʊses/ | โปรเซส |
| scheduler/ˈʃedjʊlə/ | โปรแกรมจัดสรรเวลา |
| processor/ˈprəʊsesə/ | The component that executes instructions and performs the operations of a computer or similar system. |
| memory/ˈmeməri/ | The part of a computer that holds data and programs currently in use. |
| queue/kjuː/ | A data structure in which items are normally removed in the order they were added. |
| Multi-tasking/ˈmʌlti ˈtæskɪŋ/ | The processor is switched rapidly between processes, so several appear to run at once even though only one is executing at any instant. |
| Paging/ˈpeɪdʒɪŋ/ | Memory is moved between RAM and disk so more programs can be open than physical memory allows. |
| RAM/ræm/ | Random-access memory used for working data and instructions, usually losing its contents when power is removed. |
| disk/dɪsk/ | A storage device that holds programs and data even when power is off. |
| physical memory | The actual memory hardware that holds data and programs currently in use. |
| Spooling/ˈspuːlɪŋ/ | Output for a slow device is queued on disk, so the processor never waits for a printer. Caching keeps recently used data in fast memory so it need not be fetched again. |
| Caching/ˈkæʃɪŋ/ | The process of keeping recently used data in fast memory for quicker access. |
| user interface/ˈjuːzə ˈɪntəfeɪs/ | The controls, displays and interaction mechanisms through which a person communicates with a computer system or program. |
| command line | A place where users type text commands to interact with a computer. |
| GUI | A user interface that lets people interact using visual elements. |
| ready/ˈredi/ | Describes a process that can run and is waiting for the processor. |
| Round robin/raʊnd ˈrɒbɪn/ | A scheduling method that gives each ready process a fixed time slice in turn. |
| time slice/taɪm slaɪs/ | A short interval of processor time allocated to a task before another task may run. |
| first come first served | A scheduling method that runs processes in the order they become ready. |
| shortest job first | A scheduling method that selects the ready process with the shortest expected running time. |
| shortest remaining time | A scheduling method that selects the process with the least expected time left to run. |
| New | Being created. Ready: able to run, waiting only for the processor. Running: currently executing. Blocked : waiting for something else, usually input or output. Terminated : finished. |
| Blocked/blɒkt/ | Describes a process that cannot continue until an event occurs. |
| Terminated | Describes a process that has finished running or has been stopped. |
| I/O | The transfer of data into or out of a computer or process. |
| ready queue | A list of processes waiting for the processor so they can run. |
| context switch/ˈkɒntekst swɪtʃ/ | การสลับบริบท |
| registers/ˈredʒɪstəz/ | A small, fast storage location within a processor used to hold data, addresses or instructions temporarily. |
| program counter/ˈprəʊɡræm ˈkaʊntə/ | A register that holds the address of the next instruction to be fetched. |
| process control block/ˈprəʊses kənˈtrəʊl blɒk/ | บล็อกควบคุมกระบวนการ |
| interrupts/ˈɪntərʌpts/ | Signals or events that cause normal processor execution to be suspended while service routines handle them. |
| kernel/ˈkɜːnl/ | The central part of an operating system that manages resources and provides core services to programs. |
| core/kɔː/ | The central or most important part of a system or region. |
| timer interrupt | A signal from a timer that returns control to the operating system. |
| pre-emptive scheduling | A method where the operating system can stop a running process and give another process time on the processor. |
ทำไมเมาส์ยังเคลื่อนที่ได้แม้ทุกอย่างจะหยุดนิ่ง
- โปรแกรมค้าง: หน้าจอไม่รีเฟรช, สปีนเนอร์หยุดหมุน, ไม่มีอะไรตอบสนอง แต่เมาส์ยังเลื่อนไปมาบนหน้าจอได้เหมือนเดิม
- That is the operating system telling you something: the machine is not stuck, one process is. The scheduler is still handing out slices of the processor, and the frozen program is simply not doing anything useful with its.
- ทรัพยากรทุกอย่างในเครื่องถูกแบ่งปันแบบนี้: โปรเซสเซอร์ด้วยเวลา หน่วยความจำด้วยพื้นที่ และเครื่องพิมพ์ด้วยคิว
- บทเรียนนี้จะอธิบายว่าระบบปฏิบัติการ (OS) ใช้ทรัพยากรเหล่านี้ให้เกิดประโยชน์สูงสุดได้อย่างไร และจัดการกระบวนการตั้งแต่การเริ่มต้นจนสิ้นสุดอย่างไร

การใช้ทรัพยากรให้คุ้มค่าที่สุด
- มัลติทาสกิ้ง (Multi-tasking): ตัวประมวลผลสลับไปมาระหว่างกระบวนการอย่างรวดเร็ว ทำให้หลายกระบวนการดูเหมือนทำงานพร้อมกัน ทั้งที่ในความเป็นจริงมีเพียงกระบวนการเดียวที่กำลังทำงานอยู่ในแต่ละวินาที
- เพจจิ้ง (Paging): ข้อมูลถูกย้ายระหว่างหน่วยความจำ RAM และดิสก์ เพื่อให้สามารถเปิดโปรแกรมได้มากกว่าขนาดของหน่วยความจำทางกายภาพที่มีอยู่
- สปูลลิ่ง (Spooling): ผลลัพธ์จากอุปกรณ์ที่ทำงานช้าจะถูกจัดคิวไว้บนดิสก์ ทำให้ตัวประมวลผลไม่ต้องรอเครื่องพิมพ์ แคชชิ่ง (Caching) เก็บข้อมูลที่เพิ่งใช้งานไว้ในหน่วยความจำความเร็วสูง เพื่อไม่ให้ต้องดึงข้อมูลออกมาอีกครั้ง
- ระบบปฏิบัติการยังซ่อนทุกสิ่งเหล่านี้ไว้ภายใต้ อินเทอร์เฟซผู้ใช้ (User Interface) ซึ่งอาจเป็นบรรทัดคำสั่งหรือกราฟิก (GUI)

Multi-tasking lets several programs appear to run at once by:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The OS rapidly switches the single CPU between processes so they all seem to progress together.
ตัวอย่างฝึกทำ: ทำไมสปูลลิ่งถึงช่วยได้
- อธิบายวิธีที่สปูลลิ่งช่วยเพิ่มประสิทธิภาพการใช้ทรัพยากรคอมพิวเตอร์ [3]
- เครื่องพิมพ์ช้ากว่าตัวประมวลผลหลายพันเท่า หากโปรแกรมส่งผลลัพธ์โดยตรงจะต้องรอทำให้ตัวประมวลผลว่างเปล่า
- ด้วยวิธีสปูลลิ่ง ผลลัพธ์จะถูกเขียนลงคิวบนดิสก์อย่างรวดเร็ว แล้วโปรแกรมจะดำเนินการต่อทันที
- กระบวนการแยกต่างหากจะนำข้อมูลไปพิมพ์ด้วยความเร็วของตัวเอง ในขณะที่มีหลายงานรออยู่ และตัวประมวลผลสามารถไปทำงานอื่นต่อได้ ชื่ออุปกรณ์ที่ช้า คิว และสิ่งที่ตัวประมวลผลทำแทน

Spooling helps the system because:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Spooling buffers print jobs to disk so the fast CPU is not held up by the slow printer.
Which techniques help an OS get the most from its resources? Select ทั้งหมด that apply.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Sharing time, queueing for slow devices and keeping hot data close. Killing waiting processes would lose the user's work, not improve utilisation.
กระบวนการและตัวจัดตารางเวลา
- Process คือโปรแกรมที่กำลังทำงาน: โค้ด, สถานะปัจจุบัน, หน่วยความจำ และไฟล์ที่เปิดอยู่ โปรแกรมบนดิสก์ไม่ใช่ process; โปรแกรมที่กำลังรันคือ process
- Scheduler ตัดสินใจว่า Ready process ตัวไหนจะทำงานต่อไปและนานแค่ไหน วัตถุประสงค์คือการทำให้โปรเซสเซอร์ทำงานต่อเนื่อง, ตอบสนองผู้ใช้แบบอินเทอร์แอคทีฟไว, และยุติธรรม
- เรานด์โรบิน (Round robin) ให้แต่ละกระบวนการที่พร้อมมี Slice เวลา ที่กำหนดไว้ แล้วส่งกลับไปที่ท้ายคิว: ง่าย เป็นธรรม และตอบสนองดี นโยบายอื่นๆ ได้แก่ First come first served, Shortest job first และ Shortest remaining time

ทุกคนได้รับโอกาสใช้ และไม่มีใครถือครองโปรเซสเซอร์ไว้
Round-robin scheduling gives each ready process a fixed time slice, then moves it to the back of the queue — making it fair and responsive.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Equal time slices in turn stop any one process hogging the CPU, so interactive programs stay responsive.
What is a process?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The file on disk is a program; once it is loaded and running, with state of its own, it is a process.
สถานะของกระบวนการ
- ใหม่: ถูกสร้างขึ้นมา พร้อมใช้งาน: สามารถทำงานได้ รอเพียงโปรเซสเซอร์ กำลังทำงาน: กำลังดำเนินการอยู่ ถูกกักกัน: รอสิ่งอื่นอยู่ โดยทั่วไปคือรอการรับหรือส่งข้อมูล สิ้นสุด: ทำงานเสร็จสิ้นแล้ว
- การเปลี่ยนสถานะคือสิ่งที่ข้อสอบถามมา เปลี่ยนจาก Running เป็น Ready เมื่อ Slice เสร็จสิ้น เปลี่ยนจาก Running เป็น Blocked เมื่อกระบวนการขอ I/O เปลี่ยนจาก Blocked เป็น Ready เมื่อ I/O เสร็จสิ้น เปลี่ยนจาก Ready เป็น Running เมื่อ Scheduler เลือกมัน
- ระวังความไม่สมมาตร: กระบวนการที่_blocked จะไม่กลับไปยัง Running โดยตรง มันจะกลับเข้า Ready Queue และรอ turno ของมันเอง

ห้าสถานะ และเหตุผลของแต่ละลูกศร
Match each process state to what it means.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A process cycles ready → running → (blocked) → ready, until it terminates.
ตัวอย่างฝึกทำ: ติดตามกระบวนการ
- เมื่อโปรเซสกำลังอ่านไฟล์ จะเกิดอะไรขึ้นกับมัน?
- มันเปลี่ยนจาก Running เป็น Blocked เพราะไม่สามารถดำเนินต่อได้จนกว่าข้อมูลจะมา และ Scheduler จะมอบตัวประมวลผลให้กับกระบวนการ Ready อื่นทันทีโดยไม่รอ
- เมื่อดิสก์ทำงานเสร็จ กระบวนการจะเปลี่ยนจาก Blocked เป็น Ready มันจะไม่ resumes ทันที แต่จะเข้าไปอยู่ใน Ready Queue
- Scheduler เลือกมันในภายหลัง และมันจะเปลี่ยนจาก Ready เป็น Running ดำเนินต่อจากจุดที่หยุดไว้พอดี
The life of a process
Tap round the loop a process travels. It only runs when the scheduler picks it; needing I/O sends it to blocked, and finishing its time slice sends it back to ready — round and round until it's done.
A running process asks to read a file. Put what happens to it in order.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A blocked process never returns straight to running: it rejoins the ready queue and waits its turn.
Context Switching
- เพื่อเปลี่ยนโปรเซสที่กำลังทำงาน ระบบปฏิบัติการจะบันทึกสถานะปัจจุบันของโปรเซส รวมถึงรีจิสเตอร์ ตัวชี้โปรแกรมและสถานะ ลงใน บล็อคควบคุมโปรเซส จากนั้นโหลดสถานะของโปรเซสถัดไปจากบล็อคของตัวเอง
- นั่นคือ Context Switch ซึ่งมีต้นทุนจริง: ระหว่างนั้นตัวประมวลผลกำลังทำงานบ้าน ไม่ใช่งานของผู้ใช้
- ดังนั้น Time slice จึงเป็นการประนีประนอม: ยาวเกินไปโปรแกรมอินเทอร์แอคทีฟจะรู้สึกช้า; สั้นเกินไปเครื่องจะเสียเวลาสลับงานแทนที่จะคำนวณ

A context switch involves:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The OS saves the running process's registers/PC to its PCB and loads the next process's — a small overhead each switch.
During a context switch, a process's registers and program counter are saved into its ____.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The next process's state is then loaded from its own block. The saving and loading is real work, which is what makes switching cost time.
Interrupts และ Kernel
- คิเนล, แก่นกลางของระบบปฏิบัติการ คือสิ่งที่ปฏิบัติจริง: ตอบสนองต่อ สัญญาณรบกวน จากอุปกรณ์และโปรแกรม และสัญญาณรบกวนคือสิ่งที่คืนการควบคุมให้ระบบปฏิบัติการจากโปรเซสที่กำลังทำงาน
- A timer interrupt at the end of a time slice is what makes pre-emptive scheduling possible at all; without it a program that never yields would keep the processor for ever.
- นั่นคือคำตอบสำหรับปริศนาเปิด: โปรแกรมที่หยุดนิ่งไม่ยึดครองโปรเซสเซอร์เกินกว่าช่วงเวลาที่กำหนด ทำให้เมาส์สามารถเคลื่อนที่ได้
คะแนนที่หลุดหายไป
- Process คือโปรแกรมที่กำลังทำงาน ไม่ใช่ไฟล์บนดิสก์
- Blocked to ready, never blocked straight to running. The scheduler chooses when it runs again.
- Context switch บันทึกและกู้คืนสถานะผ่าน PCB และมีต้นทุนด้านเวลา
- Multi-tasking means processes take turns so quickly they appear simultaneous, not that they truly execute at once on one core.
คุณเข้าใจแล้ว
- OS เพิ่มประสิทธิภาพการใช้ทรัพยากรโดย multi-tasking, paging, spooling ไปยัง disk queue และ caching
- a process is a program in execution; the scheduler picks the next ready one, with round robin giving each a fixed time slice
- สถานะ new, ready, running, blocked, terminated: slice expiry ส่ง running เป็น ready, request I/O ส่งไป blocked, I/O completion ส่งกลับเป็น ready
- Context switch บันทึกและกู้คืนสถานะผ่าน PCB และมีต้นทุนเวลา นี่คือเหตุผลที่ความยาวของ slice เป็นการแลกเปลี่ยน
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้