1. Operating system design

1. Operating system design

An operating system acts as an intermediary between the user of a computer and the computer hardware, it provides an environment for the execution of programs

OS services

Operating system provides certain services to programs and users

(1) User Interface

Including command line interface, graphical interface and batch interface which executes command by executing files

(2) Program Execution

Load program into memory, execute and stop it

(3) I/O Operations

For efficiency and protection, users usually cannot control I/O devices directly. Therefore, the operating system must provide a means to do I/O.

(4) File-system Manipulation

create, delete, read, write, search files

(5) Communications

occur between processes executing on the same or different computers. These may be implemented by shared memory or message passing

(6) Error Detection

The operating system needs to be detecting and correcting errors constantly

(7) Resources Allocation

When there are multiple users or multiple jobs running at the same time, resources must be allocated to each of them.

(8) Accounting

We want to keep track of which users use how much and what kinds of computer resources

(9) Protection and Security

Should not have interfere between different processes. Accessing to resources should be controlled

Command interpreter

UNIX, among other operating systems implements most commands through system programs.

rm file.txt

This command would search for a file called rm, load the file into memory, and execute it with the parameter file.txt

System call

System calls provide an interface to the services made available by an operating system. These calls are generally available as routines written in C and C++, although certain low-level tasks

For example: reading data from one file and copy them to another file

As you can see, even simple programs may make heavy use of the operating system. Most programmers never see this level of detail, application developers design programs according to an application programming interface (API)(windows api, posix api and java api), designing a program using API can expect the program to compile and run on any system that supports the same API. Furthermore, actual system calls can often be more detailed and difficult to work

In the case of UNIX and Linux for programs written in the C language, the library is called libc

Six categories of system call: process control(进程控制), file manipulation(文件管理), device manipulation(设备管理), information maintenance(信息维护), communications(通信), and protection(防护)

OS Structure

Operating systems are large and complex software projects, a common approach is to partition the task into small components rather than have a huge monolithic(庞大的) system.

MS-DOS OS: The interfaces and levels of functionality are not well defined, it was written to provide the most functionality in the least space,so it was no tcarefully divided into modules. e.g , application programs are able to access the basic I/O routines.

Original Unix OS: Like MS-DOS, UNIX initially was limited by hardware functionality. It consists of two separable parts:  the kernel and the system programs.

Everything below the system-call interface and above the physical hardware is the kernel. The kernel provides the file system, CPU scheduling, memory management, and other operating-system functions through system calls.

Taken in sum,that is an enormous amount of functionality to be combined into one level. This monolithic structure was difficult to implement and maintain.

Layerd Appoach: With proper hardware support, operating systems can be broken down into pieces that are smaller and more appropriate than those allowed in the MS-DOS and UNIX systems. 操作系统分为若干层,较高层建立在较低层,0层为硬件,最高层是用户接口

adv: simplicity of construction and debugging (自底向上), Clear interfaces between layers

disadv: hard to appropriately defining the various layers, low efficiency if too many layers

Microkernal: As UNIX expanded, the kernel became large and difficult to manage. 可以使用微内核的方法来模块化内核,这种方法将所有非基本部分从内核中移除,并将他们当作系统程序和用户程序来实现

The main function of the microkernel is to provide communication through message passing between the client program and the various services that are also running in user space

adv: extending the operating system easier(All new services are added to user space and consequently donot requiremodification of the   kernel), easier to port, more security and reliability.

disadv: the performance of microkernels can suffer due to increased system-function overhead

Modules: Perhaps the best current methodology for operating-system design involves using loadable kernel modules — kernel has a set of core components and links in additional services via modules.

adv: No need to rebuild the kernel to add functionality, efficient as new functionality can operate in kernel mode so do not need to invoke message passing in order to communicate.