The operating system

An operating system is a set of running programs that handle the interactions between the computer (in all its parts) and its users. The operating system assigns memory to each program and protects each assigned memory segment from unauthorized access (so that a malfunctioning program cannot bring the whole computer to a halt); it shares the CPU times amongst all the running processes; it operates all data exchanges with external devices (keybord, screen, network, printers, disks). Operating systems have three main parts.

A process is a program being run. In practice, the computer keeps track of the machine code instruction being executed for each running process. The operating system kernel stores information on currently running processes on its process table (this lists for example the memory segments reserved for and by the process, the amount of CPU time used by the process and so on). Processes may in turn be segmented into threads, which can be seen as separate processes which do not have a separate entry on the process table.

Any time a C++ program is compiled and linked, an executable file consisting of the equivalent machine code instructions is created. Upon launching this executable, the operating system creates a new corresponding process in the process table, and then starts executing the machine code instructions during the CPU time slices allocated to it. By calling the operating system function fork(), a C/C++ program can create a new process in the process table with a copy of itself (this means that at the clock tick immediately after the fork call has finished, the two processes are indistinguishable, save for a different process ID and different allocated CPU time slices -- later on, conditional instruction usually differentiates the two processes: this is the standard way of creating new processes from within a C/C++ program). Threads can be dealt with by linking against special libraries, but this is outside the scope of this document.

Leo Liberti 2008-01-12