The components of an operating system are designed to ensure that various parts of a computer function cohesively. With the de facto obsoletion of
DOS, all user
software must interact with the operating system to access hardware.
Kernel The kernel is the part of the operating system that provides
protection between different applications and users. This protection is key to improving reliability by keeping errors isolated to one program, as well as security by limiting the power of
malicious software and protecting private data, and ensuring that one program cannot monopolize the computer's resources. Most operating systems have two modes of operation: in
user mode, the hardware checks that the software is only executing legal instructions, whereas the kernel has
unrestricted powers and is not subject to these checks. The kernel also manages
memory for other processes and controls access to
input/output devices.
Program execution The operating system provides an interface between an application program and the computer hardware, so that an application program can interact with the hardware only by obeying rules and procedures programmed into the operating system. The operating system is also a set of services which simplify development and execution of application programs. Executing an application program typically involves the creation of a
process by the operating system
kernel, which assigns memory space and other resources, establishes a priority for the process in multi-tasking systems, loads program binary code into memory, and initiates execution of the application program, which then interacts with the user and with hardware devices. However, in some systems an application can request that the operating system execute another application within the same process, either as a subroutine or in a separate thread, e.g., the
LINK and
ATTACH facilities of
OS/360 and successors.
Interrupts An
interrupt (also known as an
abort,
exception,
fault,
signal, or
trap) provides an efficient way for most operating systems to react to the environment. Interrupts cause the
central processing unit (CPU) to have a
control flow change away from the currently running program to an
interrupt handler, also known as an interrupt service routine (ISR). An interrupt service routine may cause the
central processing unit (CPU) to have a
context switch. The details of how a computer processes an interrupt vary from architecture to architecture, and the details of how interrupt service routines behave vary from operating system to operating system. However, several interrupt functions are common. Software interrupts are similar to hardware interrupts — there is a change away from the currently running process. Similarly, both hardware and software interrupts execute an
interrupt service routine. Software interrupts may be normally occurring events. It is expected that a
time slice will occur, so the kernel will have to perform a
context switch. A
computer program may set a timer to go off after a few seconds in case too much data causes an algorithm to take too long. Software interrupts may be error conditions, such as a malformed
machine instruction. The syntax is INT X, where X is the offset number (in
hexadecimal format) to the
interrupt vector table.
Signal To generate
software interrupts in
Unix-like operating systems, the kill(pid,signum)
system call will send a
signal to another process. pid is the
process identifier of the receiving process. signum is the signal number (in
mnemonic format) to be sent. (The abrasive name of kill was chosen because early implementations only terminated the process.) In Unix-like operating systems,
signals inform processes of the occurrence of asynchronous events. One reason a process needs to asynchronously communicate to another process solves a variation of the classic
reader/writer problem. The writer receives a pipe from the
shell for its output to be sent to the reader's input stream. The
command-line syntax is alpha | bravo. alpha will write to the pipe when its computation is ready and then sleep in the wait queue. bravo will then be moved to the
ready queue and soon will read from its input stream. The kernel will generate
software interrupts to coordinate the piping. Some computers require an interrupt for each character or word, costing a significant amount of CPU time.
Direct memory access (DMA) is an architecture feature to allow devices to bypass the CPU and access
main memory directly. (Separate from the architecture, a device may perform direct memory access to and from main memory either directly or via a bus.)
Input/output Drivers The operating system includes
device drivers to access input/output devices.
Interrupt-driven I/O When a
computer user types a key on the keyboard, typically the character appears immediately on the screen. Likewise, when a user moves a
mouse, the
cursor immediately moves across the screen. Each keystroke and mouse movement generates an
interrupt called
Interrupt-driven I/O. An interrupt-driven I/O occurs when a process causes an interrupt for every character transmitted.
Direct memory access Devices such as
hard disk drives,
solid-state drives, and
magnetic tape drives can transfer data at a rate high enough that interrupting the CPU for every byte or word transferred, and having the CPU transfer the byte or word between the device and memory, would require too much CPU time. Data is, instead, transferred between the device and memory independently of the CPU by hardware such as a
channel or a
direct memory access controller; an interrupt is delivered only when all the data is transferred. If a
computer program executes a
system call to perform a block I/O
write operation, then the system call might execute the following instructions: • Set the contents of the CPU's
registers (including the
program counter) into the
process control block. • Create an entry in the device-status table. The operating system maintains this table to keep track of which processes are waiting for which devices. One field in the table is the
memory address of the process control block. • Place all the characters to be sent to the device into a
memory buffer. • Set the buffer size (an integer) to another predetermined register. Upon accepting the interrupt request, the operating system will: • Push the contents of the
program counter (a register) followed by the
status register onto the
call stack. • Pop from the call stack the registers other than the status register and program counter. • Pop from the call stack the status register. • Pop from the call stack the address of the next instruction, and set it back into the program counter. With the program counter now reset, the interrupted process will resume its time slice.
Concurrency Concurrency refers to the operating system's ability to carry out multiple tasks simultaneously. Virtually all modern operating systems support concurrency.
Threads enable splitting a process' work into multiple parts that can run simultaneously. The number of threads is not limited by the number of processors available. If there are more threads than processors, the operating system
kernel schedules, suspends, and resumes threads, controlling when each thread runs and how much CPU time it receives. During a
context switch a running thread is suspended, its state is saved into the
thread control block and stack, and the state of the new thread is loaded in. Historically, on many systems a thread could run until it relinquished control (
cooperative multitasking). Because this model can allow a single thread to monopolize the processor, most operating systems now can
interrupt a thread (
preemptive multitasking). Threads have their own thread ID,
program counter (PC), a
register set, and a
stack, but share code,
heap data, and other resources with other threads of the same process. Thus, there is less overhead to create a thread than a new process. On single-CPU systems, concurrency is switching between processes. Many computers have multiple CPUs.
Parallelism with multiple threads running on different CPUs can speed up a program, depending on how much of it can be executed concurrently.
File system s allow users and programs to organize and sort files on a computer, often through the use of
directories (or folders). Permanent storage devices used in twenty-first century computers, unlike
volatile dynamic random-access memory (DRAM), are still accessible after a
crash or
power failure. Permanent (
non-volatile) storage is much cheaper per byte, but takes several orders of magnitude longer to access, read, and write. The two main technologies are a
hard drive consisting of
magnetic disks, and
flash memory (a
solid-state drive that stores data in electrical circuits). The latter is more expensive but faster and more durable.
File systems are an
abstraction used by the operating system to simplify access to permanent storage. They provide human-readable
filenames and other
metadata, increase performance via
amortization of accesses, prevent multiple threads from accessing the same section of memory, and include
checksums to identify
corruption. File systems are composed of files (named collections of data, of an arbitrary size) and
directories (also called folders) that list human-readable filenames and other directories. An absolute
file path begins at the
root directory and lists
subdirectories divided by punctuation, while a relative path defines the location of a file from a directory.
System calls (which are sometimes
wrapped by libraries) enable applications to create, delete, open, and close files, as well as link, read, and write to them. All these operations are carried out by the operating system on behalf of the application. The operating system's efforts to reduce latency include storing recently requested blocks of memory in a
cache and
prefetching data that the application has not asked for, but might need next.
Device drivers are software specific to each
input/output (I/O) device that enables the operating system to work without modification over different hardware. Another component of file systems is a
dictionary that maps a file's name and metadata to the
data block where its contents are stored. Most file systems use directories to convert file names to file numbers. To find the block number, the operating system uses an
index (often implemented as a
tree). Separately, there is a free space
map to track free blocks, commonly implemented as a
bitmap. Although any free block can be used to store a new file, many operating systems try to group together files in the same directory to maximize performance, or periodically reorganize files to reduce
fragmentation. Maintaining data reliability in the face of a computer crash or hardware failure is another concern. File writing protocols are designed with atomic operations so as not to leave permanent storage in a partially written, inconsistent state in the event of a crash at any point during writing. Data corruption is addressed by redundant storage (for example, RAID—
redundant array of inexpensive disks) and
checksums to detect when data has been corrupted. With multiple layers of checksums and backups of a file, a system can recover from multiple hardware failures. Background processes are often used to detect and recover from data corruption.
Networking Modern operating systems usually include a
network stack, such as the
TCP/IP protocol stack.
Security Security means protecting users from other users of the same computer, as well as from those who seeking remote access to it over a network. Operating systems security rests on achieving the
CIA triad: confidentiality (unauthorized users cannot access data), integrity (unauthorized users cannot modify data), and availability (ensuring that the system remains available to authorized users, even in the event of a
denial of service attack). As with other computer systems, isolating
security domains—in the case of operating systems, the kernel, processes, and
virtual machines—is key to achieving security. Other ways to increase security include simplicity to minimize the
attack surface, locking access to resources by default, checking all requests for authorization,
principle of least authority (granting the minimum privilege essential for performing a task),
privilege separation, and reducing shared data. Some operating system designs are more secure than others. Those with no isolation between the kernel and applications are least secure, while those with a
monolithic kernel like most general-purpose operating systems are still vulnerable if any part of the kernel is compromised. A more secure design features
microkernels that separate the kernel's privileges into many separate security domains and reduce the consequences of a single kernel breach.
Unikernels are another approach that improves security by minimizing the kernel and separating out other operating systems functionality by application. Most operating systems are written in
C or
C++, which create potential vulnerabilities for exploitation. Despite attempts to protect against them, vulnerabilities are caused by
buffer overflow attacks, which are enabled by the lack of
bounds checking. Hardware vulnerabilities, some of them
caused by CPU optimizations, can also be used to compromise the operating system. There are known instances of operating system programmers deliberately implanting vulnerabilities, such as
back doors. Operating systems security is hampered by their increasing complexity and the resulting inevitability of bugs. Because
formal verification of operating systems may not be feasible, developers use operating system
hardening to reduce vulnerabilities, e.g.
address space layout randomization,
control-flow integrity,
access restrictions, and other techniques. There are no restrictions on who can contribute code to open source operating systems; such operating systems have transparent change histories and distributed governance structures. Open source developers strive to work collaboratively to find and eliminate security vulnerabilities, using
code review and
type checking to expunge malicious code.
Andrew S. Tanenbaum advises releasing the
source code of all operating systems, arguing that it prevents developers from placing trust in secrecy and thus relying on the unreliable practice of
security by obscurity.
User interface A
user interface (UI) is essential to support human interaction with a computer. The two most common user interface types for any computer are •
command-line interface, where computer commands are typed, line-by-line, •
graphical user interface (GUI) using a visual environment, most commonly a combination of the window, icon, menu, and pointer elements, also known as
WIMP. For personal computers, including
smartphones and
tablet computers, and for
workstations, user input is typically from a combination of
keyboard,
mouse, and
trackpad or
touchscreen, all of which are connected to the operating system with specialized software. Personal computer users who are not software developers or coders often prefer GUIs for both input and output; GUIs are supported by most personal computers. The software to support GUIs is more complex than a command line for input and plain text output. Plain text output is often preferred by programmers, and is easy to support. ==Operating system development as a hobby==