What an operating system does
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
Windows, macOS, Linux, Android and iOS are operating systems: the program that manages the hardware for every other program. See its core, the kernel, start apps as processes, share the CPU by switching between them many times a second, give each its own memory, keep files on the disk and talk to devices through drivers, while apps ask for all of it with system calls.
5 أسئلة سريعة
اختر إجابة لتعرف السبب. تُحفَظ نتيجتك مع تقدّمك.
01What is a process?
A program is the instructions stored on the disk. When the OS loads it into memory and starts it, the running program is called a process.
02One CPU core and three open apps. How do all three seem to run at once?
A core runs one process at a time. A timer wakes the kernel every few milliseconds, which saves where one process stopped and loads the next (a context switch). It is so fast that all three seem to run together.
03The browser tries to change the music player's memory. What happens?
The OS gives every process its own part of memory, and the hardware it sets up blocks access to anyone else's. That is why one app cannot read or break another.
04In Python, f = open("list.txt", "w") runs. What does the program do to reach the disk?
Apps run in user mode and cannot touch the hardware. open() ends up as a system call, a request to the kernel, whose file system and disk driver do the work.
05What is a device driver?
Every kind of device is controlled differently. A driver hides those details: apps ask the OS to play sound, and the sound driver talks to the speaker.
المسرد
- Operating system (OS)
- The program that manages the hardware for every other program, such as Windows, macOS, Linux, Android or iOS.
- Kernel
- The core of the OS. It runs in kernel mode, with full control of the hardware, and sits between the apps and the hardware.
- Process
- A running program: its code and data loaded into memory, plus where it has got to.
- Scheduler
- The part of the kernel that decides which process runs on the CPU next, and for how long.
- Context switch
- Saving exactly where one process stopped and loading where the next one stopped, so the CPU can switch between them.
- System call
- A request from an app to the kernel for a service, such as opening a file or playing sound.
- Device driver
- Code in the OS that knows how to control one kind of device, such as a disk or a speaker.
- User mode / kernel mode
- Two levels the CPU enforces: apps run in user mode with limits; the kernel runs in kernel mode with full control.
الملاحظات والمصادر
- Most CPUs today have several cores, and each core runs one process at a time, so a few processes really do run at the same moment. The OS still switches every core between many processes.
- How long a time slice lasts depends on the OS and on how busy the computer is. The OSTEP textbook uses a timer that interrupts every 10 milliseconds as its example, which would allow about 100 switches a second.
- Each process really gets its own virtual address space. Hardware in the CPU, set up by the kernel, translates it to real memory. A process that touches memory it does not own gets an error (on Linux, a segmentation fault) and is normally stopped.
- Python's open(), and the write and close it does later, end up as system calls (on Linux: openat, write and close). The names differ on Windows and macOS, but the idea is the same.
- Most drivers run inside the kernel, as drawn here. Some systems also run parts of drivers as ordinary programs in user mode.
- The code card is real Python 3: run it and it creates list.txt containing the text milk.
- Arpaci-Dusseau, Operating Systems: Three Easy Pieces, ch. 4: The Abstraction: The Process
- OSTEP ch. 6: Limited Direct Execution (user and kernel mode, system calls, timer interrupt, context switch)
- OSTEP ch. 7: Scheduling: Introduction (time slices)
- OSTEP ch. 13: The Abstraction: Address Spaces (isolation)
- OSTEP ch. 36: I/O Devices (device drivers)
- OSTEP ch. 39: Files and Directories (open, write, close)
- Microsoft Learn: User mode and kernel mode
- Microsoft Learn: What is a driver?
- Linux man-pages: syscalls(2)
- Python Library Reference: open()
- Python Library Reference: io (buffered streams)
- Android Open Source Project: Kernel overview
اختبار يتاح بعد الخطوة الأخيرة.