0% found this document useful (0 votes)
31 views24 pages

5u Linux

Linux is a versatile operating system used across various devices, managing hardware resources and facilitating communication between software and hardware. It consists of several components including the kernel, system libraries, and utilities, and is known for its open-source nature, allowing users to modify and distribute it freely. Key features include multi-user capabilities, multitasking, a hierarchical file system, and robust security measures.

Uploaded by

oltofer9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views24 pages

5u Linux

Linux is a versatile operating system used across various devices, managing hardware resources and facilitating communication between software and hardware. It consists of several components including the kernel, system libraries, and utilities, and is known for its open-source nature, allowing users to modify and distribute it freely. Key features include multi-user capabilities, multitasking, a hierarchical file system, and robust security measures.

Uploaded by

oltofer9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

UNIT 5: CASE STUDY ON LINUX

LINUX Operating System?

• From smartphones to cars, supercomputers and home appliances, the Linux operating
system is everywhere.

What is Linux?
Just like Windows XP, Windows 7, Windows 8, and Mac OS X, Linux is an operating system. An
operating system is software that manages all of the hardware resources associated with your
desktop or laptop. To put it simply – the operating system manages the communication between
your software and your hardware. Without the operating system (often referred to as the “OS”),
the software wouldn’t function.

The OS is comprised of a number of pieces:

The Boot loader: The software that manages the boot process of your computer. For most
users, this will simply be a splash screen that pops up and eventually goes away to boot
into the operating system.

The kernel: This is the one piece of the whole that is actually called “Linux”. The kernel
is the core of the system and manages the CPU, memory, and peripheral devices. The kernel
is the “lowest” level of the OS.

Daemons: These are background services (printing, sound, scheduling, etc) that either start
up during boot, or after you log into the desktop.

The Shell: You’ve probably heard mention of the Linux command line. This is the shell
– a command process that allows you to control the computer via commands typed into a
text interface. This is what, at one time, scared people away from Linux the most (assuming
they had to learn a seemingly archaic command line structure to make Linux work). This
is no longer the case. With modern desktop Linux, there is no need to ever touch the
command line.

Graphical Server: This is the sub-system that displays the graphics on your monitor. It is
commonly referred to as the X server or just “X”.

Desktop Environment: This is the piece of the puzzle that the users actually interact with.
There are many desktop environments to choose from (Unity, GNOME, Cinnamon,
Enlightenment, KDE, XFCE, etc). Each desktop environment includes built-in applications
(such as file managers, configuration tools, web browsers, games, etc).

Applications: Desktop environments do not offer the full array of apps. Just like Windows
and Mac, Linux offers thousands upon thousands of high-quality software titles that can
1
be easily found and installed. Most modern Linux distributions (more on this in a moment)
include App Store-like tools that centralize and simplify application installation. For
example: Ubuntu Linux has the Ubuntu Software Center (Figure 1) which allows you to
quickly search among the thousands of apps and install them from one centralized location.

Linux is also distributed under an open source license. Open source follows the following key
philosophies:

The freedom to run the program, for any purpose.

The freedom to study how the program works, and change it to make it do what you wish.
The freedom to redistribute copies so you can help your neighbor.

The freedom to distribute copies of your modified versions to others.

Components of Linux System


Linux Operating System has primarily three components

Kernel − Kernel is the core part of Linux. It is responsible for all major activities of this
operating system. It consists of various modules and it interacts directly with the
underlying hardware. Kernel provides the required abstraction to hide low level hardware
details to system or application programs.

System Library − System libraries are special functions or programs using which
application programs or system utilities accesses Kernel's features. These libraries
implement most of the functionalities of the operating system and do not requires kernel
module's code access rights.

System Utility − System Utility programs are responsible to do specialized, individual


level tasks.

Kernel Mode vs User Mode


2
Kernel component code executes in a special privileged mode called kernel mode with full access
to all resources of the computer. This code represents a single process, executes in single address
space and do not require any context switch and hence is very efficient and fast. Kernel runs each
processes and provides system services to processes, provides protected access to hardware to
processes.

Support code which is not required to run in kernel mode is in System Library. User programs
and other system programs works in User Mode which has no access to system hardware and
kernel code. User programs/ utilities use System libraries to access Kernel functions to get
system's low level tasks.

Basic Features
Following are some of the important features of Linux Operating System.

Portable − Portability means software can works on different types of hardware in same
way. Linux kernel and application programs supports their installation on any kind of
hardware platform.

Open Source − Linux source code is freely available and it is community based
development project. Multiple teams work in collaboration to enhance the capability of
Linux operating system and it is continuously evolving.

Multi-User − Linux is a multiuser system means multiple users can access system
resources like memory/ ram/ application programs at same time.

Multiprogramming − Linux is a multiprogramming system means multiple applications


can run at same time.

Hierarchical File System − Linux provides a standard file structure in which system files/
user files are arranged.

Shell − Linux provides a special interpreter program which can be used to execute
commands of the operating system. It can be used to do various types of operations, call
application programs. etc.

Security − Linux provides user security using authentication features like password
protection/ controlled access to specific files/ encryption of data.

Architecture of a Linux system


The following illustration shows the architecture of a Linux system −
3
The architecture of a Linux System consists of the following layers −

Hardware layer − Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).

Kernel − It is the core component of Operating System, interacts directly with hardware,
provides low level services to upper layer components.

Shell − An interface to kernel, hiding complexity of kernel's functions from users. The
shell takes commands from the user and executes kernel's functions.

Utilities − Utility programs that provide the user most of the functionalities of an operating
systems.

Design principles of Linux


• Linux is a multi-user, multitasking system with a full set of UNIX-compatible tools..
4
• 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.
• 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.

Describe Linux kernel with appropriate diagram.

• The Linux kernel is a Unix-like computer operating system kernel. The Linux operating
system is based on it and deployed on both traditional computer systems such as
personal computers and servers, usually in the form of Linux distributions,[9]and on
various embedded devices such as routers, wireless access points, PBXes, set-top boxes,
FTA receivers, smart TVs, PVRs and NAS appliances. The Android operating system for
tablet computers, smart phones and smart watches is also based atop the Linux kernel.
• The Linux kernel API, the application programming interface (API) through which user
programs interact with the kernel, is meant to be very stable and to not break
user space programs (some programs, such as those with GUIs, rely on other APIs as
well). As part of the kernel's functionality, device drivers control the hardware;
"mainlined" device drivers are also meant to be very stable. However, the interface
between the kernel and loadable kernel modules (LKMs), unlike in many other kernels
and operating systems, is not meant to be very stable by design.

• The kernel sits directly on the hardware and enables interactions with I/O devices and the
memory management unit and controls CPU access to them. At the lowest level, as shown
in Fig. it contains interrupt handlers, which are the primary way for interacting with
devices, and the low-level dispatching mechanism. This dispatching occurs when an
interrupt happens. The low-level code here stops the running process, saves its state in the
kernel process structures, and starts the appropriate driver. Process dispatching also

5
happens when the kernel completes some operations and it is time to start up a user process
again. The dispatching code is in assembler and is quite distinct from scheduling.

• Next, we divide the various kernel subsystems into three main components. The I/O
component in Fig. 10-3 contains all kernel pieces responsible for interacting with devices
and performing network and storage I/O operations. At the highest level, the I/O operations
are all integrated under a VFS (Virtual File System) layer. That is, at the top level,
performing a read operation on a file, whether it is in memory or on disk, is the same as
performing a read operation to retrieve a character from a terminal input. At the lowest
level, all I/O operations pass through some device driver. All Linux drivers are classified
as character-device drivers or block-device drivers, the main difference being that seeks
and random accesses are allowed on block devices and not on character devices.

KERNEL MODULES
The Linux kernel has the ability to load and unload arbitrary sections of kernel code
on demand. These loadable kernel modules run in privileged kernel mode and as a
6
consequence have full access to all the hardware capabilities of the machine on which
they run.

A kernel module can implement device driver, a file system, or a networking protocol.

Kernel modules are convenient for several reasons. Linux’s source code is free, so anybody
wanting to write kernel code is able to compile a modified kernel and to reboot into that
new functionality. If you use kernel modules, you do not have to make a new kernel to
test a new driver - the driver can be compiled on its own and loaded into the already
running kernel.

Once a new, driver is written, it can be distributed as a module so that other users can
benefit from it without having to rebuild their kernels.

The module support under Linux has four components:

1. The module-management system allows modules to be loaded into memory and to


communicate with the rest of the kernel.

2. The module loader and unloader, which are user-mode utilities, work with the
module-management system to load a module into memory.

3. The driver-registration system allows modules to tell the rest of the kernel that a new
driver has become available.

4. A conflict-resolution mechanism allows different device drivers to reserve hardware


resources and to protect those resources from accidental use by another driver.

Module Management

Loading a module requires more than just loading its binary contents into kernel memory.
The system must also make sure that any references the module makes to kernel symbols
or entry points are updated to point to the correct locations in the kernel’s address space.
Linux deals with this reference updating by splitting the job of module loading into two
separate sections:

1. The management of sections of module code in kernel memory.

2. The handling of symbols that modules are allowed to reference.

The loading of the module is performed in two stages:

First, the module loader utility asks the kernel to reserve a continuous area of virtual
kernel memory for the module. The kernel returns the address of the memory allocated,
and the loader utility can use this address to relocate the module’s machine code to the
correct loading address.

7
A second system call then passes the module, plus any symbol table that the new
module wants to export, to the kernel. The module itself is now copied verbatim into
the previously allocated space, and the kernel’s symbol table is updated with the new
symbols for possible use by other modules not yet loaded.

The final module-management component is the module requester. The kernel defines
a communication interface to which a module-management program can connect. With
this connection established, the kernel will inform the management process whenever a
process requests a device driver, file system, or network service that is not currently
loaded and will give the manager the opportunity to load that service. The original
service request will complete once the module is loaded.

The manager process regularly queries the kernel to see whether a dynamically loaded
module is still in use and unloads that module when it is no longer actively needed

Driver Registration

A module may register many types of functionality; it is not limited to only one type. For
example, a device driver might want to register two separate mechanisms for accessing the
device. Registration tables include, among others, the following items:

Device Drivers: These drivers include character devices (such as printers,


terminals, and mice), block devices (including all disk drives), and network
interface devices.

File systems: The file system may be anything that implements Linux’s virtual
file system calling routines.

Network protocols: A module may implement an entire networking protocol,


such as TCP or simply a new set of packet-filtering rules for a network firewall.

Binary format: This format specifies a way of recognizing, loading, and


executing a new type of executable file.

Conflict Resolution

Linux provides a central conflict-resolution mechanism to help arbitrate access to


certain hardware resources. Its aims are as follows:

o To prevent modules from clashing over access to hardware resources.

o To prevent auto probes - device-driver probes that auto-detect device


configuration - from interfering with existing device drivers.

o To resolve conflicts among multiple drivers trying to access the same


hardware. for example, when both the parallel printer driver and the parallel
8
line IP (PLIP) network driver try to talk to the parallel port.

Process Management
• Processes carry out tasks within the operating system. A program is a set of machine code

9
instructions and data stored in an executable image on disk and is, as such, a passive entity;
a process can be thought of as a computer program in action.
• During the lifetime of a process it will use many system resources. It will use the CPUs
in the system to run its instructions and the system's physical memory to hold it and its
data. It will open and use files within the file systems and may directly or indirectly use the
physical devices in the system.
• Linux must keep track of the process itself and of the system resources that it has so that it can
manage it and the other processes in the system fairly. It would not be fair to the other processes
in the system if one process monopolized most of the system's physical memory or its CPUs.

• The most precious resource in the system is the CPU, usually there is only one. Linux is
a multiprocessing operating system, its objective is to have a process running on each
CPU in the system at all times, to maximize CPU utilization. If there are more processes
than CPUs (and there usually are), the rest of the processes must wait before a CPU
becomes free until they can be run.

• Processes are created in Linux in an especially simple manner. The fork system call creates
an exact copy of the original process. The forking process is called the parent process.
The new process is called the child process. The parent and child each have their own,
private memory images. If the parent subsequently changes any of its variables, the
changes are not visible to the child, and vice versa.

• Process Identifier is when each process has a unique identifier associated with it known as
process id.

• User and Group Identifiers (UID and GID) are the identifiers associated with a processes
of the user and group.

• The new process are created by cloning old process or current process. A new task is
created by a system call i.e fork or clone. The forking process is called parent process and
the new process is called as child process.

Linux Processes

• State:- As a process executes it changes state according to its circumstances. Linux


10
processes have the following states:

• Running:- The process is either running (it is the current process in the system) or it is
ready to run (it is waiting to be assigned to one of the system's CPUs).

• Waiting:- The process is waiting for an event or for a resource. Linux differentiates
between two types of waiting process; interruptible and uninterruptible. Interruptible
waiting processes can be interrupted by signals whereas uninterruptible waiting processes
are waiting directly on hardware conditions and cannot be interrupted under any
circumstances.

• Stopped:- The process has been stopped, usually by receiving a signal. A process that is
being debugged can be in a stopped state.

• Zombie:- This is a halted process which, for some reason, still has a data structure in
the task vector. It is what it sounds like, a dead process.

• Scheduling Information:- The scheduler needs this information in order to fairly decide
which process in the system most deserves to run,

• Identifiers:- Every process in the system has a process identifier. The process identifier
is not an index into the task vector, it is simply a number. Each process also has User and
group identifiers, these are used to control this processes access to the files and devices in
the system,

• Inter-Process Communication:- Linux supports the classic Unix IPC mechanisms of


signals, pipes and semaphores and also the System V IPC mechanisms of shared memory,
semaphores and message queues.

• Links:- In a Linux system no process is independent of any other process. Every process
in the system, except the initial process has a parent process. New processes are not created,
they are copied, or rather cloned from previous processes

• Times and Timers:- The kernel keeps track of a processes creation time as well as the
CPU time that it consumes during its lifetime. Each clock tick, the kernel updates the
amount of time that the current process has spent in system and in user mode. Linux also
supports process specific interval timers, processes can use system calls to set up timers to
send signals to themselves when the timers expire. These timers can be single- shot or
periodic timers.
• Virtual memory:- Most processes have some virtual memory (kernel threads and daemons
do not) and the Linux kernel must track how that virtual memory is mapped onto the
system's physical memory.

• Processor Specific Context:- A process could be thought of as the sum total of the
system's current state. Whenever a process is running it is using the processor's registers,
11
stacks and so on.

• File system:- Processes can open and close files as they wish and the processes contains
pointers to descriptors for each open file as well as pointers to two VFS. Each VFS uniquely
describes a file or directory within a file system and also provides a uniform interface to
the underlying file systems.

Process Management System Calls in Linux


• Processes are the most fundamental abstraction in a Linux system, after files. As object
code in execution - active, alive, running programs - processes are more than just assembly
language; they consist of data, resources, state, and a virtualized computer.
• Linux took an interesting path, one seldom traveled, and separated the act of reating a new
process from the act of loading a new binary image. Although the two tasks are performed
in tandem most of the time, the division has allowed a great deal of freedom for
experimentation and evolution for each of the tasks. This road less traveled has survived
to this day, and while most operating systems offer a single system call to start up a new
program, Linux requires two: a fork and an exec.

Creation and termination

Syscall Description
CLONE Create a child process
FORK Create a child process
VFORK Create a child process and block parent
EXECVE Execute program
EXECVEAT Execute program relative to a directory file descriptor
EXIT Terminate the calling process
EXIT_GROUP Terminate all threads in a process
WAIT4 Wait for process to change state
WAITID Wait for process to change state
Pocess id

Syscall Description
GETPID Get process ID
GETPPID Get parent process ID
GETTID Get thread ID

Session id

12
Syscall Description
SETSID Set session ID
GETSID Get session ID

Process group id

Syscall Description
SETPGID Set process group ID
GETPGID Get process group ID
GETPGRP Get the process group ID of the calling process

Users and groups

Syscall Description
SETUID Set real user ID
GETUID Get real user ID
SETGID Set real group ID
GETGID Get real group ID
SETRESUID Set real, effective and saved user IDs
GETRESUID Get real, effective and saved user IDs
SETRESGID Set real, effective and saved group IDs
GETRESGID Get real, effective and saved group IDs
SETREUID Set real and/or effective user ID
SETREGID Set real and/or effective group ID
SETFSUID Set user ID used for file system checks
SETFSGID Set group ID used for file system checks
GETEUID Get effective user ID
GETEGID Get effective group ID
SETGROUPS Set list of supplementary group IDs
GETGROUPS Get list of supplementary group IDs

Scheduling in Linux

13
• Linux threads are kernel threads, so scheduling is based on threads, not processes.

• Linux distinguishes three classes of threads for scheduling purposes:

1. Real-time FIFO.

2. Real-time round robin.

3. Timesharing.

• Real-time FIFO threads are the highest priority and are not preemptable except by a newly
readied real-time FIFO thread with even higher priority. Real-time round robin threads are
the same as real-time FIFO threads except that they have e time quanta associated with
them, and are preemptable by the clock. If multiple real-time round- robin threads are
ready, each one is run for its quantum, after which it goes to the end of the list of real-time
round-robin threads. Neither of these classes is actually real time in any sense. Deadlines
cannot be specified and guarantees are not given. These classes are simply higher priority
than threads in the standard timesharing class.

• The Completely Fair Scheduler (CFS) is a process scheduler which was merged into
the Linux kernel and is the default scheduler. It handles CPU resource allocation for
executing processes, and aims to maximize overall CPU utilization while also maximizing
interactive performance.

Memory management in Linux.

14
The term “memory management” refers to the mechanisms implemented by an operating system to
provide applications with memory-related services.
These services include usage of virtual memory (utilizing of a hard disk or other non-RAM storage media to
provide additional program memory), protected memory (exclusive access to a region of memory by a
process), and shared memory (cooperative access to a region of memory by multiple processes).
Memory management services in the Linux are built on a programming foundation that includes a
peripheral device called Memory Management Unit (MMU). MMU translates physical memory addresses to
linear addresses used by the operating system, and requests a page fault interrupt, when the CPU tries
to access memory that it is not entitled to.
For further understanding of structure of the MM services, we need to know that a basic unit of
memory under Linux is page, a non-overlapping region of contiguous memory. All available physical
memory is organized into pages towards the end of the kernel’s boot process. Size of page depends
on processor architecture. Processor designs often allow to have two or more, sometimes simultaneously, page
sizes.
Traditional page size used by Linux is 4096 bytes. But using memory pages “as is” is not very convenient.
Often we need to allocate less than one memory page. There are such possibilities in Linux:
• In the kernel, you can allocate one of the small kernel objects using slab allocator;
We can allocate a memory block by kmalloc, but it will allocate only a block of the
nearest bigger size that it has;
• In the user mode, you can allocate any amount of memory using heap management
functions implemented in Standard C Library; We can create your own heap manager
on top of the Linux kernel system calls.

To provide a simple interface for interaction with Memory Management Unit and perform such interaction in
a portable way, in Linux, subsystem of allocating and releasing memory is split into three layers.
These layers are:
1. The Slab Allocator
2. The Zone Allocator
3. The Buddy Allocator

General scheme of all these layers interaction with user mode code and hardware looks as follows

15
Note that in
Linux, most of programs directly or indirectly use heap manager of the GCC Standard C Library
called glibc, but you still can write your own heap manager on top of the kernel system calls.

As we can see above diagram, user space allocation always leads to kernel allocation. Kernel
allocates memory using the chain of three kernel allocators and maps allocated pages to the
address space of the process, which has requested the allocation.
The Buddy Allocator is responsible for the management of the page allocations in the entire system. This
code manages lists of physically contiguous pages and maps them into the MMU page tables to provide
other kernel subsystems with the valid physical address ranges, when the kernel requests them (Physical
to Virtual Address mapping is handled by a higher layer of the VM).
The Buddy Allocator splits memory into pairs of 2n pages where n is in range from 0 to
MAX_ORDER constant (defined in the header file <linux/mmzone.h>), and stores information
about the free blocks of pages in the array of lists as follows

16
Each list consists of free
physically contiguous
blocks of 2i memory
pages, where i is a list number. Each of such blocks, except the block that consists of 1 page, can be split
into two halves and used as 2 blocks of a half size.
So if no entries exist in the requested list, an entry from the next upper list is broken into two
separate clusters and one is returned to the caller while the other one is added to the next lower list.

On the other hand, every two blocks of memory of the same size, which have common border (arranged
in memory sequentially, from the standpoint of physical addresses), may be united into the single block
of the bigger size. Such neighbouring blocks are called Buddies.
When allocation is returned to the Buddy Allocator, it checks if buddy of the allocation is free, and if it is
so, Buddy Allocator unites them into the bigger block. This operation is repeated until no more block
buddies are found.
Also we should note that the Buddy Allocator can allocate only blocks of the size in pages that is equal to
2 raised to some power.
The Buddy Allocator also interacts with the kernel threads kswapd and bdflush, which are responsible
for the maintaining with the swap.
Different ranges of physical pages may have different properties, for the purposes of the kernel.
For example, Direct Memory Access can work only in specific range of physical addresses in the x86
architecture. On the other hand PPC does not have this constraint.
For handling such situation in a hardware, independent way the Zone Allocator was created.
The Zone Allocator is used to allocate pages in the specified zone. Today Linux kernel is supporting
three memory zones

DMA: This zone consists of memory accessible for direct memory operations of the legacy
devices.
NORMAL: This zone includes memory addresses used by the kernel for internal data structures
as well as other system and user space allocations.
HIGHMEM: This zone includes all memory used exclusively for system allocations (file
system buffers, user space allocations, etc).
17
Note that the Zone Allocator also can manipulate only with memory pages.
Since we often need to allocate objects that have size less than the size of a page, we need something to
deal with the pages and allocate lesser chunks of memory for us.
We know the sizes of the most objects that are often allocated in the kernel space, so we can create
allocator that will receive pages of memory from the Zone Allocator and allocate small objects
in these memory pages. This subsystem is named the Slab Allocator (An Object-Caching Kernel
Memory Allocator).

The Slab Allocator organizes memory in caches, one cache for each object type, e.g. inode_cache,
dentry_cache, buffer_head, vm_area_struct. Each cache consists of many slabs (usually one page long),
and each slab contains multiple initialized objects.
This means that the constructor of the objects is used only for newly allocated slabs and you should
initialize object before release it to the Slab Allocator.
Also the Slab Allocator makes it possible to allocate buffers of memory of one of the specially defined
sizes. Such buffers can be got using kernel function kmalloc. You specify the size of allocation, and
kmalloc will allocate block of the greater size, the nearest to the one you requested. Sizes of memory
blocks, which can be allocated by kmalloc, are available in the header file <linux/kmalloc_sizes.h>.

Also the kernel can allocate virtually contiguous memory (memory with contiguous virtual addresses,
but not with contiguous physical addresses) using vmalloc function.

18
File Systems
• To the user, 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).

• The Linux VFS is designed around object-oriented principles and is composed of two components:

➢ A set of definitions that define what a file object is allowed to look like

✔ The inode-object and the file-object structures represent individual files

✔ the file system object represents an entire file system

➢ A layer of software to manipulate those objects.

The Linux Ext2fs File System

• 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.

➢ In ffs, the disk is allocated to files in blocks of 8Kb, with blocks being subdivided into
fragments of 1Kb to store small files or partially filled blocks at the end of a file.

➢ Ext2fs does not use fragments; it performs its allocations in smaller units. The default
block size on ext2fs is 1Kb, although 2Kb and 4Kb blocks are also supported.

➢ Ext2fs uses allocation policies designed to place logically adjacent blocks of a file
into physically adjacent blocks on disk, so that it can submit an I/O request for several
disk blocks as a single operation.
19
Ext2fs Block-Allocation Policies

The

Linux Proc File System

• The proc file system does not store data, rather, its contents are computed on demand according to
user file I/O requests.

• proc must implement a directory structure, and the file contents within; it must then define a unique
and persistent inode number for each directory and files it contains.

➢ It uses this inode number to identify just what operation is required when a user tries
to read from a particular file inode or perform a lookup in a particular directory inode.

➢ When data is read from one of these files, proc collects the appropriate information,
formats it into text form and places it into the requesting process’s read buffer.

20
Input and Output
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.

• Linux splits all devices into three classes:

➢ Block devices allow random access to completely independent, fixed size blocks of data.

➢Character devices include most other devices; they don’t need to support the functionality of
regular files.

➢Network devices are interfaced via the kernel’s networking Subsystem

Device-driver Block Structure

21
Block Devices
• Provide the main interface to all disk devices in a system.
• The block buffer cache serves two main purposes:

➢ it acts as a pool of buffers for active I/O

➢ it serves as a cache for completed I/O

• The request manager manages the reading and writing of buffer contents to and from a block device
driver.

Character Devices

• A device driver which does not offer random access to fixed blocks of data.
•A character device driver must register a set of functions which implement the driver’s various file I/O
operations.
•The kernel performs almost no preprocessing of a file read or write request to a character device, but
simply passes on the request to the device.
•The main exception to this rule is the special subset of character device drivers which implement terminal
devices, for which the kernel maintains a standard interface.

22
Interprocess Communication
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.

Passing Data Between Processes


• The pipe mechanism allows a child process to inherit a communication channel to its parent, data
written to one end of the pipe can be read a the other.

• Shared memory offers an extremely fast way of communicating; any data written by one process
to a shared memory region can be read immediately by any other process that has mapped that
region into its address space.

• To obtain synchronization, however, shared memory must be used in conjunction with another
Interprocess communication mechanism.
23
Shared Memory Object
• The shared-memory object acts as a backing store for shared-memory regions in the same way as
a file can act as backing store for a memory-mapped memory region.

• Shared-memory mappings direct page faults to map in pages from a persistent shared memory
object.

• Shared-memory objects remember their contents even if no processes are currently mapping them
into virtual memory.

24

You might also like