100% found this document useful (1 vote)
147 views

CH1-Introduction To Unix Linux Kernel

The document discusses the structure and architecture of UNIX/Linux operating systems. It covers the system structure, file subsystem, process control subsystem, and concepts like inodes, file tables, and descriptors. Key components include the kernel, system calls, device drivers, memory and process management.

Uploaded by

Vishal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
147 views

CH1-Introduction To Unix Linux Kernel

The document discusses the structure and architecture of UNIX/Linux operating systems. It covers the system structure, file subsystem, process control subsystem, and concepts like inodes, file tables, and descriptors. Key components include the kernel, system calls, device drivers, memory and process management.

Uploaded by

Vishal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Chapter 1

Introduction to UNIX /Linux Kernel

❖ System Structure

❖ Architecture of UNIX Operating System

❖ Introduction to System Concepts.

- Overview of file subsystem, processes, context of process, process states,

state transitions, sleep and wakeup

Ms. Rupali Pise (Computer Science)


Introduction to UNIX /Linux Kernel

❖ The UNIX system has become quite popular since its inception in 1969, running on machine of varying
processing power from microprocessors to mainframes and providing a common execution environment
across all of them.

❖ The system is divided into two parts.

1. The first part consists of programs and services that have made the UNIX system environment so
popular; it is the part readily apparent to users, including such programs as the shell, mail, text
processing packages, and source code control systems.

2. The second part consists of the operating system that supports these programs and services

Ms. Rupali Pise (Computer Science)


Introduction of an Operating System

❖ System Structure:
▪ High-level architecture of the UNIX system.
▪ The hardware at the center of the diagram provides the
operating system with basic services
▪ The operating system interacts directly with the hardware·,
providing common services to programs.
▪ Viewing the system as a set of layers, the operating system
is commonly called the system kernel.
▪ Kernel emphasizing its separation from user programs,
Because programs are independent of the underlying
hardware, it is easy to move them between UNIX systems
running on different hardware.

Ms. Rupali Pise (Computer Science)


Introduction of an Operating System

❖ Programs such as the shell and editors (ed and vi) shown in the outer layers interact with the kernel by
invoking a well defined set of system calls.
❖ The system calls instruct the kernel to do various operations for the calling program and exchange data
between the kernel and the program.
❖ Several programs shown in the figure are in standard system configurations and are known as Commands,
but private user programs may also exist in this layer as indicated by the program whose name is a.out, it is
standard name for executable files produced by the C compiler.
❖ Other application programs can build on top of lower-level programs, hence the existence of the outermost
layer in the figure. For example, the standard C compiler.
❖ Although the figure depicts a two-level hierarchy of application programs, users can extend the hierarchy to
whatever levels are appropriate.

Ms. Rupali Pise (Computer Science)


Architecture of Unix System

❖ Architecture of Unix System:


▪ Following block diagram serves as a useful logical view of the kernel, showing various modules and
their relationships to each other.
▪ Two major components of the kernel : file subsystem (left) and the process control subsystem (right).
▪ Figure shows three levels: user, kernel, and hardware.
▪ The system call and library interface represent the border between user programs and the kernel
▪ System calls look like ordinary function calls in C programs, and libraries map these function calls to
the primitives needed to enter the operating system.
▪ Assembly language programs may invoke system calls directly without a system call library.
▪ However programs frequently use other libraries such as the standard I/0 library to provide a more
sophisticated use of the system calls.

Ms. Rupali Pise (Computer Science)


Architecture
of
Unix System

Ms. Rupali Pise (Computer Science)


Architecture of Unix System
❖ The set of system calls interact with
1. The file subsystem
2. The process control subsystem.

❖ The file subsystem manages files, allocating file space, administering free space, controlling access to files, and
retrieving data for users.

❖ Processes interact with the file subsystem via a specific set of system calls, such as open (to open a file for
reading or writing), close, read, write, stat (query the attributes of a file), chown (change the record of who
owns the file), and chmod (change the access permissions of a file) .

❖ The file subsystem accesses file data using a buffering mechanism that regulates data flow between the kernel
and secondary storage devices.

❖ The buffering mechanism interacts with block I/O device drivers to initiate data transfer to and from the kernel.

❖ Device drivers are the kernel modules that control the operation of peripheral devices. Block I/O devices are
random access storage devices.

Ms. Rupali Pise (Computer Science)


Architecture of Unix System

❖ The process control subsystem is responsible for process synchronization, Interprocess communication memory
management, and process scheduling.

❖ The file subsystem and the process control subsystem interact when loading a file into memory for execution.

❖ The process subsystem reads executable files into memory before executing them; Some of the system calls for
controlling processes are fork ,exec (overlay the image of a program onto the running process), exit ,wait, brk
(control the size of memory allocated to a process), and signal (control process response to events).

❖ The memory management module controls the allocation of memory.


▪ If at any time the system does not have enough physical memory for all processes, the kernel moves them
between main memory and secondary memory so that all processes get a fair chance to execute.

Ms. Rupali Pise (Computer Science)


Architecture of Unix System
❖ Two policies for managing memory: swapping and demand paging.

▪ The scheduler module allocates the CPU to processes.

▪ It schedules them to until the kernel preempts them when their run time exceeds a time quantum.

▪ The scheduler then chooses the highest priority eligible process to run; the original process will run again
when it is the highest priority eligible process available.

❖ Finally, the hardware control is responsible for handling interrupts and for communicating with the machine.

❖ Devices such as disks or terminals may interrupt the CPU while a process is executing.

❖ If so, the kernel may resume execution of the interrupted process after servicing the interrupt.

❖ Interrupts are not serviced by special processes but by special functions in the kernel, called in the context of
the currently running process.

Ms. Rupali Pise (Computer Science)


Introduction to System Concepts

❖ An Overview of File Subsystem:


▪ The internal representation of a file is given by an inode, which contains a description of the disk layout
of the file data and other information such as the file owner, access permissions, and access times.

▪ The term inode (index node) is commonly used in literature on the UNIX system.

▪ Every file has one inode, but it may have several names, all of which map into the inode.

▪ When a process refers to a file by name, the kernel parses the file name one component at a time,
checks that the process has permission to search the directories in the path, and eventually retrieves
the inode for the file.

Ms. Rupali Pise (Computer Science)


An Overview of File Subsystem

▪ The kernel contains data structures : file table, user file and descriptor table .

▪ The file table is a global kernel structure, but the user file descriptor table is allocated per process.

▪ When a process opens or creates a file, the kernel allocates an entry from each table, corresponding to
the file's inode.

▪ Entries in the three structures - user file descriptor table, file table, and inode table -maintain the state
of the file and the user's access to it.

▪ The file table keeps track of the byte offset in the file where the user's next read or write will start, and
the access rights allowed to the opening process.

▪ The user file descriptor table identifies all open files for a process.

Ms. Rupali Pise (Computer Science)


An Overview of File Subsystem
▪ Following figure shows the tables and their relationship to each other.
▪ The kernel returns a file descriptor for the open and creat system calls, which is an index into the user
file descriptor table.
▪ When executing read and write system calls, the kernel uses the file descriptor to access the user file
descriptor table, follows pointers to the file table and inode table entries, and, from the inode, finds the
data in the file.

Ms. Rupali Pise (Computer Science)


An Overview of File Subsystem

▪ The UNIX system keeps regular files and directories on block devices such as tapes or disks. Because of the
access time of both are different.

▪ Partitioning a disk into several file systems makes it easier to manage the data store.

▪ The conversion between logical device (file system) addresses and physical device (disk) addresses is done
by the disk driver.

▪ A file system consists of a sequence of logical blocks, each containing 512, 1024, 2048, or any convenient
multiple of 512 bytes, depending on the system implementation.

▪ The size of a logical block is homogeneous within a file system but may vary between different file systems in
a system configuration.

▪ Using large logical blocks increases the effective data transfer rate between disk and memory, because the
kernel can transfer more data per disk operation and therefore make fewer time-consuming operations.

Ms. Rupali Pise (Computer Science)


An Overview of File Subsystem

❖ A file system has the following structure


1. The boot block occupies the beginning of a file system, typically the first sector, and may contain the
bootstrap code that is read into the machine to boot, or initialize, the operating system. Although only
one boot block is needed to boot the system, every file system has a boot block.

2. The super block describes the state of a file system - how large it is, how many files it can store, where
to find free space on the file system, and other information.

Ms. Rupali Pise (Computer Science)


An Overview of File Subsystem

❖ A file system has the following structure


3. The inode list is a list of inodes that follows the super block in the file system. The kernel references
inodes by index into the inode list.
▪ One inode is the root inode of the file system: it is the inode by which the directory structure of
the file system is accessible after execution of the mount() system call.

4. The data blocks start at the end of the inode list and contain file data and administrative data. An
allocated data block can belong to one and only one file in the file system.

Ms. Rupali Pise (Computer Science)


Processes

❖ Process:

▪ A process is the execution of a program

▪ Process consists of a pattern of bytes that the CPU interprets as machine instructions (called "text"),
data, and stack.

▪ Many processes execute simultaneously as the kernel schedules them for execution, and several
processes may be instances of one program.

▪ A process executes by following a strict sequence of instructions that is self-contained and does not
jump to another process; it reads and writes its data and stack sections, but it cannot read or write
the data and stack of other processes.

▪ Processes communicate with other processes via system calls.

Ms. Rupali Pise (Computer Science)


Processes

▪ In UNIX system , a process is the entity that is created by the fork() system call.

▪ Every process except process 0 is created when another process executes the fork system call.

▪ The process that invoked the fork system call is the parent process, and the newly created process is the
child process.

▪ Every process has one parent process, but a process can have many child processes.

▪ The kernel identifies each process by its process number, called the process ID (PID).

▪ Process 0 is a special process that is created "by hand" when the system boots; after forking a child
process (process 1), process 0 becomes the swapper process

▪ Process 1, known as init, is the ancestor of every other process in the system and enjoys a special
relationship with them,

Ms. Rupali Pise (Computer Science)


Context of Process
▪ The context of a process is its state, as defined by its text, the values of its global user variables and data
structures, the values of machine registers it uses, the values stored in its process table slot and u area, and
the contents of its user and kernel stacks.

▪ When the kernel decides that it should execute another process, it does a context switch, so that the
system executes in the context of the other process.

▪ The kernel allows a context switch only under specific conditions.

▪ When doing a context switch, the kernel saves enough information so that it can later switch back to the
first process and resume its execution.

▪ The interrupted process may have been executing in user mode or in kernel mode.

▪ Moving between user and kernel mode is a change in mode, not a context switch.

▪ The kernel does a context switch when it changes context from process A to process B; it changes execution
mode from user to kernel or from kernel to user.

Ms. Rupali Pise (Computer Science)


Process states

▪ The lifetime of a process can be divided into a set of states, each with certain characteristics that
describe the process.

▪ To understand the following process states now:


1. The process is currently executing in user mode.
2. The process is currently executing in kernel mode.
3. The process is not executing, but it is ready to run as soon as the scheduler chooses it. Many processes
may be in this state, and the scheduling algorithm determines which one will execute next.
4. The process is sleeping. A process puts itself to sleep when it can no longer continue executing, such as
when it is waiting for I/0 to complete.

Ms. Rupali Pise (Computer Science)


Process states

▪ The processor can execute only one process at a


time, at most one process may be in states 1 and 2.
▪ The two states correspond to the two modes of
execution, user and kernel.

Process States and Transitions Diagram

Ms. Rupali Pise (Computer Science)


State transitions

▪ The process states give a static view of a process, but processes move continuously between the states
according to well-defined rules.

▪ A state transition diagram is a directed graph whose nodes represent the states a process can enter and
whose edges represent the events that cause a process to move from one state to another.

▪ State transitions are legal between two states if there exists an edge from the first state to the second.

▪ Several transitions may produce from a state, but a process will follow one and only one transition depending
on the system event that occurs.

▪ Several processes can execute simultaneously in a time-shared manner, and they may all run simultaneously
in kernel mode.

Ms. Rupali Pise (Computer Science)


State transitions

▪ If they were allowed to run in kernel mode without constraint, they could corrupt global kernel data
structures.

▪ By prohibiting arbitrary context switches and controlling the occurrence of interrupts, the kernel protects
its consistency

▪ The kernel allows a context switch only when a process moves from the state "kernel running" to the
state "asleep in memory."

▪ Processes running in kernel mode cannot be preempted by other processes; therefore the kernel is
sometimes said to be non-preemptive, although the system does preempt processes that are in user
mode.

▪ The kernel maintains consistency of its data structures because it is non-preemptive, thereby solving the
mutual exclusion problem - making sure that critical sections of code are executed by at most one process
at a time.

Ms. Rupali Pise (Computer Science)


State transitions

▪ The UNIX system prevents such 'situations by disallowing context switches’ when a process executes
in kernel mode.

▪ If a process goes to sleep, thereby permitting a context switch, kernel algorithms are encoded to make
sure that system data are in a safe, consistent state.

▪ The kernel protects its consistency by allowing a context switch only when a process puts itself to sleep
and by preventing one process from changing the state of another process.

▪ It also raises the processor execution level around critical regions of code to prevent interrupts that
could otherwise cause inconsistencies.

▪ The process scheduler periodically preempts processes executing in user mode so that processes cannot
monopolize use of the CPU.

Ms. Rupali Pise (Computer Science)


Sleep and wakeup
❖ A process executing in kernel mode has great autonomy in deciding what it is going to do in reaction to
system events.

❖ For instance, when a process must temporarily suspend its execution then "go to sleep".

❖ Consequently, an interrupt handler cannot go to sleep, because if it could, the interrupted process would
be put to sleep by default.

❖ Processes go to sleep because they are awaiting the occurrence of some event, such as waiting for I/0
completion from a peripheral device, waiting for a process to exit, waiting for system resources to
become available, and so on.

❖ Processes are said to sleep on an event, meaning that they are in the sleep state until the event occurs,
at which time they wake up and enter the state "ready to run”.

❖ When a process wakes up, it follows the state transition from the "sleep" state to the "ready-to-run"
state, where it is eligible for later scheduling; it does not execute immediately.

Ms. Rupali Pise (Computer Science)


Sleep and wakeup

▪ Many processes can simultaneously sleep on an event; when an event occurs, all processes sleeping on the
event wake up because the event condition is no longer true.

▪ Sleeping processes do not consume CPU resources: The kernel does not constantly check to see that a
process is still sleeping but waits for the event to occur and then awakens the process.

▪ The kernel implements such locks in the following manner:

while (condition is true)


sleep (event: the condition becomes false);
set condition true;

▪ It unlocks the lock and awakens all processes asleep on the lock in the following manner:

set condition false;


wakeup (event: the condition is ·false);

Ms. Rupali Pise (Computer Science)

You might also like