Learning Programming with Eas — the Tutorial by Molaskes

How the Computer Works:13. The Operating System

An operating system is a computer's main program that handles all I/O ports, controls all interrupts and timers, implements a file system and so on, and can run sub-programs. These sub-programs use defined communication protocols to use the operating system's services, such as all the above mentioned (I/O, interrupts, file system and so on) and a standardized user interface ("windows", user I/O, etc.). They each get their own restricted portion of RAM and they are not standalone programs that handle all the hardware ports and registers themselves, they are rather like extensions for the operating-system main program that can be added (started) and removed (exited) during runtime. These sub-programs may have a user interface and then are called "executables" (*.exe), "applications", or just simply "programs", or they run in the background as auxiliary tools for either the operating system itself or for other programs, and then may be called "dynamically linked libraries" (*.dll), "auxiliary processes", or other such names, depending on the operating system. Operating systems allow various such processes, auxiliary and applications, to run "simultaneously", which is called multi-tasking. Of course, the program pointer only moves every clock tick and nothing is really simultaneous, but the processes proceed in small bursts in a roundabout fashion so that all can be started at the same time and progress in their tasks seemingly parallel to each other. The operating system either calls modules of the processes like functions and needs to wait until they return, which is called cooperative multi-tasking, or it uses a timer to switch between the processes, each time saving and restoring the program pointer, which is called preemptive multi-tasking. Especially in preemptive multi-tasking, the operating system gives the processes each different times to run the next burst, balanced for their priority, as some processes may be doing intensive calculations while others just idly wait for some user input to happen. For processing-intensive times, each process may actively request a higher or allow a lower priority when weighted against others, and/or the user can make this setting in the operating system for each application. Here's an illustration of coperative multi-tasking:
OS: Okay, process A, your turn!
P-A: Dumdidumdidumdidum. Done!
OS: Thanks. Now, process B, your turn!
P-B: Diddldididdlidi.Done!
OS: Thanks. Now again process A!
P-A: Dudumdidumdidumdidumdumdum. Done!
OS: Thanks. Now again process B!
And now preemptive multitasking:
OS: Process A, proceed!
P-A: Dumdidumd—
OS: STOP! That's enough. Process B!
P-B: Diddldididdli—
OS: STOP! That's enough. Process A!
P-A: —idumdi—
OS: STOP! That's enough. Process B!
13. The Operating System
T Two Things You Need
C Contact
Esc Search / Table of Contents