Installing Linux
◾
317
It is the operating system that decides if and how the action should be carried out. First,
the operating system must decide if the request is permissible. Does the user have adequate
access rights to the resource? Second, the operating system will decide how the item is to
be treated. A file, for instance, can be opened with full access or as a read-only file. Third,
the operating system issues the command(s) to the resource(s) by communicating through
the appropriate device driver(s).
This leads us to a discussion of how access is controlled in the computer. Most comput-
ers use two modes of execution:
user mode
and
privileged mode
. User mode should be self-
explanatory in that this is the mode for all users and in this mode, the user can only make
requests.
The privileged mode, also known as administrator mode, monitor mode, system
mode, or supervisor mode, is able to control all aspects of the computer from memory
movement to disk access to network access to handling of interrupting situations. In user
mode, any such operation is a request requiring that the operating system kernel deter-
mine if the requesting user has sufficient access to the requested resource.
Given a request, the operating system first takes control of the computer. It does so by
switching modes from user to privileged mode and then examines the request and the user
or application that generated the request. The
mode is indicated by a flag, usually stored as
1 bit in a control register of the CPU. Upon completion, the operating system changes mode
back to user mode and relinquishes control back to the user. All this is hidden from the user.
In some operating systems, there are several different levels of user modes. The Multics
operating system, for instance, had a hierarchical set of privileges. The Intel processors
starting with the 80286 introduced a protected mode to handle address space issues.
Another mode developed for Intel starting with the 286 was the real mode, used to dif-
ferentiate whether a program’s code was using newer instructions made available starting
with the 286
processor, or older code written for the original 8086 processor.
Along with the division of operating modes is a division in memory. There is the user’s
address space (or users’ address spaces) and the operating system’s address space. Requests
to access memory outside one’s address space typically lead to a
memory violation
that can
either cause a terminating error in the program or at least an interrupt to the operating
system to decide how to handle it.
The operating system, on the other hand, is free to access any or all address spaces as
needed. Within the operating system, there may be further divisions so that, for instance,
the kernel has one address space and other utility programs have their own address spaces.
In this way, errors caused by some subcomponent of the operating
system may not inter-
fere with the kernel.
8.2.2 System Calls
How do applications communicate with the operating system to place requests? This is
handled through a mechanism known as a
system call
. A system call is implemented either
as a function call or a message passed to the kernel. In Linux, system calls are implemented
as C functions.
Depending on the version of Linux you are working with, there are between 300 and
400 system calls available. The idea is that application software is programmed to place
318
◾
Linux with
Operating System Concepts
system calls so that, when the program needs to invoke the kernel, it does so by calling a
kernel function. The system call invokes the kernel that then switches mode and executes
the system call. During the execution of the system call, if the operation requested is not
appropriate for the software or user, the system call is not completed and either an error
arises or the application is informed via an error code that describes the problem.
One drawback of the system call is that it requires a good deal of overhead because the
system is switching from one process (the application) to another (the operating system),
from one mode (user) to the other (privileged), and from one address space to another.
Further, it is possible that this switch will also require the use of virtual memory.
Some examples of Linux system calls are presented in Table 8.1. Although you as a Linux
user may never have to directly deal with system calls, it is useful in understanding this
concept. As a Linux developer (whether operating system or application software), you
would have to understand system calls.
8.2.3
The Kernel
The kernel is a single program in charge of basic system operations such as process execu-
tion, memory management, resource (device) management, and interprocess communica-
tion. There are three schools of thought in designing operating system kernels: monolithic
kernels, microkernels, and hybrid kernels.
A
monolithic
kernel is one in which the kernel is a single program that operates solely
within the privileged mode and in its own address space. Communication between the user
TABLE 8.1
Examples
of Linux System Calls
Do'stlaringiz bilan baham: