Basic Operating System Concepts
The operating system must fulfill two main objectives:
- Interact with the hardware components, serving all low-level programmable elements included in the hardware platform.
- Provide an execution environment to the application that run on the computer system (the so-called user programs).
- An authentication mechanism for verifying the user's identity
- A protection mechanism against buggy user programs that could block other application running in the system
- A protection mechanism against malicious user programs that could interfere with or spy on the activity of other users
- An accounting mechanism that limits the amount of resource units assigned to each user
An Overview of the Unix Filesystem
Files
A Unix file is an information container structured as a sequence of bytes; the kernel does not interpret the contents of a file.
Unix associates a current working directory with each process; it belongs to the process execution context, and it identifies the directory currently used by the process.
Hard and Soft Links
A filename included in a directory is called a file hard link, or more simply, a link.
Hard links have two limitations:
- It is not possible to create hard links for directories.
- Links can be created only among files included in the same filesystem.
File Types
Unix files may have one of the following types:
- Regular file
- Directory
- Symbolic link
- Block-oriented device file
- Character-oriented device file
- Pipe and named pip (also called FIFO)
- Socket
File Descriptor and Inode
All information needed by the filesystem to handle a file is included in a data structure called an inode. Each file has its own inode, which the filesystem uses to identify the file.
Access Right and File Mode
The potential users of a file fall into three classes:
- The user who is the owner of the file
- The users who belong to the same group as the file, not including the owner
- All remaining users (others)
File-Handling System Calls
An Overview of Unix Kernels
The Process/Kernel Model
The process/kernel model assumes that processes that require a kernel service use specific programming constructs called system calls.
Unix kernels do much more than handle system calls; in fact, kernel routines can be activated in several ways:
- A process invokes a system call.
- The CPU executing the process signals an exception, which is an unusual condition such as an invalid instruction. The kernel handles the exception on behalf of the process that caused it.
- A peripheral device issues an interrupt signal to the CPU to notify it of an event such as a request for attention, a status change, or the completion of an I/O operation. Each interrupt signal is dealt by a kernel program called an interrupt handler.
- A kernel thread is excuted.
Process Implementation
When the kernel stops the execution of a process, it saves the current contents of several processor registers in the process descriptor.
When the kernel decides to resume executing a process, it uses the proper process descriptor fields to load the CPU registers.
When a process is not executing on the CPU, it is waiting for some event.
Reentrant Kernels
All Unix kernels are reentrant. This means that several processes may be executing in Kernel Mode at the same time.
When one of the following events occurs, the CPU interleaves the kernel control paths:
- A process executing in User Mode invokes a system call, and the corresponding kernel control path verifies that the request cannot be satisfied immediately; it then invokes the scheduler to select a new process to run.
- The CPU detects an exception -- for example, access to a page not present in RAM -- while running a kernel control path.
- A hardware interrupt occurs while the CPU is running a kernel control path with the interrupts enabled.
- An interrupt occurs while the CPU is running with kernel preemption enabled, and a higher priority process is runnable.
Process Address Space
Each process runs in its private address space.
Synchronization and Critical Regions
Kernel preemption disabling
Interrupt disabling
Semaphores
Spin locks
Avoiding deadlocks
Signals and Interprocess Communication
Unix signals provide a mechanism for notifying processes of system events.
AT&T's Unix System V introduced other kinds of interprocess communication among processes in User Mode, which have adopted by many Unix kernels: semaphores, message queues, and shared memory. They are collectively known as System V IPC.
Process Management
Zombie processes
Process groups and login sessions
Memory Management
Virtual memory
Virtual memory acts as a logical layer between the application memory requests and the hardware Memory Management Unit (MMU).
Random access memory usage
Kernel Memory Allocator
Process virtual address space handling
Caching
Device Drivers
The kernel interacts with I/O devices by means of device drivers. Device drivers are included in the kernel and consist of data structures and functions that control one or more devices. Each driver interacts with the remaining part of the kernel (even with other drivers) through a specific interface.