MOS Unit 05 Linux Operating Systems Full
MOS Unit 05 Linux Operating Systems Full
MOS Unit 05 Linux Operating Systems Full
Linux System
Linux is a modern, free operating system based on UNIX standards.
First developed as a small but self-contained kernel in 1991 by Linus
Torvalds, with the major design goal of UNIX compatibility. Linux uses
many tools developed as part of Berkeley’s BSD operating system, MIT’s
X Window System, and the Free Software Foundation’s GNU project.
The main system libraries were started by the GNU project, with
improvements provided by the Linux community. Linux networking-
administration tools were derived from 4.3BSD code. Recent BSD
derivatives such as FreeBSD have borrowed code from Linux in return.
The Linux system is maintained by a loose network of developers
collaborating over the Internet, with a small number of public ftp sites
acting as de facto standard repositories.
Design principles
Linux is a multiuser, multitasking system with a full set of UNIX-
compatible tools.
Its file system adheres to traditional UNIX semantics, and it fully
implements the standard UNIX networking model.
Main design goals are speed, efficiency, and standardization.
1
Linux is designed to be compliant with the relevant POSIX
documents; at least two Linux distributions have achieved official
POSIX certification.
The Linux programming interface adheres to the SVR4 UNIX
semantics, rather than to BSD behavior
The Linux system is composed of three main bodies of code, the most
important distinction is between the kernel and all other components.
Kernel code executes in kernel mode with full access to all the physical
resources of the computer. All kernel code and data structures are kept in
the same single address space.
2
Fig 5.1 Components of a Linux System
All the kernel code executes in the processor’s privileged mode with full
access to all the physical resources of the computer.
One of the most important user utilities is the shell, the standard
command-line interface on UNIX systems. Linux supports many shells;
the most common is the bourne-again shell (bash).
Kernel Modules
Sections of kernel code that can be compiled, loaded, and unloaded
independent of the rest of the kernel. A kernel module may typically
implement a device driver, a file system, or a networking protocol. The
module interface allows third parties to write and distribute, on their own
terms, device drivers or file systems that could not be distributed under the
GPL.
Module Management:
Supports loading modules into memory and letting them talk to the rest of
the kernel. Module loading is split into two separate sections:
Driver registration:
Allows modules to tell the rest of the kernel that a new driver has become
available. The kernel maintains dynamic tables of all known drivers,
provides a set of routines to allow drivers to be added to or removed from
these tables at any time.
Device drivers
File systems
Network protocols
Binary format
Conflict resolution:
4
Prevent auto probes from interfering with existing device drivers
Resolve conflicts with multiple drivers trying to access the same
hardware
Process Management
A process is the basic context in which all user-requested activity is
serviced within the operating system.
Under UNIX, a process encompasses all the information that the operating
system must maintain to track the context of a single execution of a single
program.
Process Identity
Environment
Context.
Process Identity
Process ID (PID): Each process has a unique identifier. The PID is used to
specify the process to the operating system when an application makes a
system call to signal, modify, or wait for the process. Additional identifiers
associate the process with a process group (typically, a tree of processes
forked by a single user command) and login session.
5
Credentials: Each process must have an associated user ID and one or more
group IDs that determine the rights of a process to access system resources
and files.
Process Environment
Process Context
Process context is the state of the running program at any one time, like
(ready, running , execution, terminated , waiting). It changes constantly.
6
Accounting: The kernel maintains accounting information about the
resources currently being consumed by each process and the total resources
consumed by the process in its entire lifetime so far.
File table: The file table is an array of pointers to kernel file structures
representing open files. When making file-I/O system calls, processes refer
to files by an integer, known as a file descriptor (fd), that the kernel uses to
index into this table.
File-system context: Whereas the file table lists the existing open files, the
file-system context applies to requests to open new files. The file-system
context includes the process’s root directory, current working directory, and
namespace.
Virtual memory context: The virtual memory context describes the full
contents of a process’s private address space. Linux provides the fork()
system call, which duplicates a process without loading a new executable
image.
Linux also provides the ability to create threads via the clone() system call.
Linux does not distinguish between processes and threads. In fact, Linux
generally uses the term task, rather than process or thread when referring to
a flow of control within a program.
The clone() system call behaves identically to fork(), except that it accepts
as arguments a set of flags that dictate what resources are shared between
the parent and child (whereas a process created with fork() shares no
resources with its parent).
7
Process Scheduling
Scheduling is the job of allocating CPU time to different tasks within an
operating system. Linux, like all UNIX systems, supports preemptive
multitasking.
In such a system, the process scheduler decides which process runs and
when. Linux has two separate process-scheduling algorithms.
Time-sharing algorithm
Completely Fair Scheduler (CFS)
Smaller nice values indicate higher priorities. Thus, by increasing the nice
value, you are decreasing your priority and being “nice” to the rest of the
system. CFS introduced a new scheduling algorithm called fair scheduling
that eliminates time slices in the traditional sense.
To start, CFS says that if there are N runnable processes, then each should
be afforded 1/N of the processor’s time. CFS then adjusts this allotment by
weighting each process’s allotment by its nice value.
Processes with the default nice value have a weight of 1 their priority is
unchanged. Processes with a smaller nice value (higher priority) receive a
higher weight, while processes with a larger nice value (lower priority)
receive a lower weight. CFS then runs each process for a “time slice”
8
proportional to the process’s weight divided by the total weight of all
runnable processes.
Memory Management
Linux’s physical memory-management system deals with allocating and
freeing pages, groups of pages, and small blocks of memory. It has
additional mechanisms for handling virtual memory, memory mapped into
the address space of running processes.
9
Fig 5.2 Relationship of zones and physical addresses in Intel x86-32
All memory allocations in the Linux kernel are made either statically by
drivers that reserve a contiguous area of memory during system boot time,
or dynamically, by the page allocator.
The most important are the virtual memory system, the kmalloc() variable-
length allocator; the slab allocator, used for allocating memory for kernel
data structures; and the page cache, used for caching pages belonging to
files.
A slab is used for allocating memory for kernel data structures and is made
up of one or more physically contiguous pages. A cache consists of one or
more slabs.
There is a single cache for each unique kernel data structure — for example,
a cache for the data structure representing process descriptors, a cache for
file objects, a cache for inodes, and so forth.
10
Fig 5.3 Slab Allocation
The slab allocator first attempts to satisfy the request with a free object in a
partial slab. If none exist, a free object is assigned from an empty slab.
The allocator uses a buddy system to keep track of available physical pages.
In this scheme, adjacent units of allocatable memory are paired together
11
(hence its name). Each allocatable memory region has an adjacent partner
(or buddy).
Whenever two allocated partner regions are freed up, they are combined to
form a larger region a buddy heap. That larger region also has a partner,
with which it can combine to form a still larger free region.
Under Linux, the smallest size allocatable under this mechanism is a single
physical page. Figure 5.3 shows an example of buddy-heap allocation.
The Virtual Memory system maintains the address space visible to each
process: It creates pages of virtual memory on demand, and manages the
loading of those pages from disk or their swapping back out to disk as
required. The Virtual Memory manager maintains two separate views of a
process’s address space:
12
Logical View: A logical view describing instructions concerning the layout
of the address space. The address space consists of a set of nonoverlapping
regions, each representing a continuous, page-aligned subset of the address
space.
The backing store, which describes from where the pages for a
region come; regions are usually backed by a file or by nothing
(demand-zero memory)
The region’s reaction to writes (page sharing or copy-on-write).
1. When a process runs a new program with the exec system call
Creating a new process with fork involves creating a complete copy of the
existing process’s virtual address space.
13
Input–Output Management
The Linux device-oriented file system accesses disk storage through two
caches:
Data is cached in the page cache, which is unified with the virtual
memory system.
Metadata is cached in the buffer cache, a separate cache indexed by
the physical disk block.
Block Devices: Provide the main interface to all disk devices in a system.
The block buffer cache serves two main purposes:
The request manager manages the reading and writing of buffer contents to
and from a block device driver.
Network devices: are dealt with differently from block and character
devices. Users cannot directly transfer data to network devices. Instead,
14
they must communicate indirectly by opening a connection to the kernel’s
networking subsystem
File System
Linux’s file system appears as a hierarchical directory tree obeying UNIX
semantics. Internally, the kernel hides implementation details and manages
the multiple different file systems via an abstraction layer, that is, the virtual
file system (VFS).
Ext2fs uses a mechanism similar to that of BSD Fast File System (ffs) for
locating data blocks belonging to a specific file. The main differences
between ext2fs and ffs concern their disk allocation policies.
15
Fig 5.5 ext3 block allocation policies
Like UNIX, Linux informs processes that an event has occurred via signals.
There is a limited number of signals, and they cannot carry information:
Only the fact that a signal occurred is available to a process.
The Linux kernel does not use signals to communicate with processes with
are running in kernel mode, rather, communication within the kernel is
accomplished via scheduling states and wait queue structures.
Mobile OS
Some important features of Mobile Operating System are
Alternate Keyboards.
Infrared Transmission.
Touch Control.
Automation.
Multi touch.
Video calling.
Screen capture.
iOS Architecture
The iOS is the operating system created by Apple Inc. for mobile devices.
The iOS is used in many of the mobile devices for apple such as iPhone,
iPod, iPad etc. The iOS is used a lot and only lags behind Android in terms
of popularity.
17
The iOS architecture is layered. It contains an intermediate layer between
the applications and the hardware, so they do not communicate directly.
The lower layers in iOS provide the basic services and the higher layers
provide the user interface and sophisticated graphics.
Core OS: All the iOS technologies are build on the low level features
provided by the Core OS layer. These technologies include Core Bluetooth
Framework, External Accessory Framework, Accelerate Framework,
Security Services Framework, Local Authorization Framework etc.
Core Services: There are many frameworks available in the cure services
layer. Details about some of these are given as follows:
Cloudkit Framework: The data can be moved between the app the
iCloud using the Cloudkit Framework.
Core Foundation Framework: This provides the data
management and service features for the iOS apps.
Core Data Framework: The data model of the model view
controller app is handled using the Core Data Framework.
18
Address Book Framework: The address book framework
provides access to the contacts database of the user.
Core Motion Framework: All the motion-based data on the
device is accessed using core motion framework.
Healthkit Framework: The health-related information of the user
can be handled by this new framework.
Core Location Framework: This framework provides the location
and heading information to the various apps.
Media Services: The media layer enables all the graphics, audio
and video technology of the system. The different frameworks are:
UIKit Graphics: This provides support for designing images and
animating the view content.
Core Graphics Framework: This provides support for 2-D vector
and image based rendering and is the native drawing engine for iOS
apps.
Core Animation: The Core Animation technology optimizes the
animation experience of the apps.
Media Player Framework: This framework provides support for
playing playlists and enables the user to use their iTunes library.
Cocoa Touch: The cocoa touch layer provides the following frameworks:
19
Android Architecture
Android operating system is a stack of software components which is
roughly divided into five sections and four main layers as shown below in
the architecture diagram.
Linux kernel: At the bottom of the layers is Linux kernel. This provides a
level of abstraction between the device hardware and it contains all the
essential hardware drivers like camera, keypad, display etc. Also, the kernel
handles networking along with interfacing to peripheral hardware.
20
A summary of some key core Android libraries available to the Android
developer is as follows:
21
Android Runtime
This is the third section of the architecture and available on the second layer
from the bottom. This section provides a key component called Dalvik
Virtual Machine which is a kind of Java Virtual Machine specially designed
and optimized for Android.
The Dalvik VM makes use of Linux core features like memory management
and multi-threading, which is fundamental in the Java language. The Dalvik
VM enables every Android application to run in its own process, with its
own instance of the Dalvik virtual machine.
The Android runtime also provides a set of core libraries which enable
Android application developers to write Android applications using
standard Java programming language.
Application Framework
22
Applications
All the Android application are available at the top layer. If we write our
application that is to be installed on this layer only. Examples of such
applications are Contacts Books, Browser, Games etc.
23