Download - Ch2

Transcript
Page 1: Ch2

Introduction to Kernel

Prepared byChandni Shah

Page 2: Ch2

Introduction to Kernel

Topics Kernel Architecture Introduction To System Concepts

File System Process

Kernel Data Structures System Administration

Page 3: Ch2

Kernel Architecture (UNIX)

Library

hardware

File Subsystem

character block

Hardware control

Buffer Cache

system call interface

Device driver

Inter process communication

Scheduler

Memory Managemen

t

Process Control Subsystem

User programUser level

kernel level

User level

kernel level

Page 4: Ch2

Overview of File Subsystem

Every file has a I-Node(index node)It contains details like disk layout of file

data ,owner, access permissions and access times.

I-node is unique to each file in Unix

Page 5: Ch2

5

What is an inode?

An inode (index node) is a control structure that contains key information needed by the OS to access a particular file.

Several file names may be associated with a single inode, but each file is controlled by exactly ONE inode.

On the disk, there is an inode table that contains the inodes of all the files in the file system.

When a file is opened, its inode is brought into main memory and stored in a memory-resident inode table.

Page 6: Ch2

Inode Table List of all I-nodes

Global File table. global to the kernel e.g. the byte offset in the file

where the user's next read/write will start the access rights allowed to the opening process. 

Process File Descriptor table. local to every process contains information like the identifiers of the files

opened by the process. Whenever, a process creates a file, it gets an index

from this table primarily known as File Descriptor. 

Data Structure for File Handling

Page 7: Ch2

Data Structure for File Handling

Inode tables interact with user process specific file descriptor tables and global file tables in Unix File System to facilitate the file handling.

Page 8: Ch2

Interaction between tables with an Example

Example:

Process A: fd1 = open("/var/file1", O_RDONLY); fd2 = open("/var/file2", O_RDWR); fd3 = open("/var/file1", O_WRONLY);

 Process B:

 fd1 = open("/var/file1", O_RDONLY); fd2 = open("/var/file3", O_RDONLY);

Page 9: Ch2

File Descriptors, File Table and Inode table

Page 10: Ch2

Explanation of figure

Each open() returns a file descriptor to the process, and the corresponding entry in the user file descriptor table points to a unique entry in the global file table even though a file(/var/file1) is opened more then once. 

These global file table entries map to the in-core inode table entry. Every opened file has a unique entry in the global file table and the user file descriptor table but kernel keeps only single entry per file in the in-core inode table.

Separate entries are created in user file descriptor and global file table, but only the reference count is increased in the inode table. All the system calls related to file handling use these tables for data manipulation.

Page 11: Ch2

File System

A file system is consists of a sequence of logical blocks (512/1024 byte etc.)

A file system has the following structure:

Boot Block Super Block Inode List Data Blocks

Page 12: Ch2

File System: Boot Block

The beginning of the file systemContains bootstrap code to load the operating

systemInitialize the operating systemTypically occupies the first sector of the disk

Page 13: Ch2

File System: Super Block

Describes the state of a file systemDescribes the size of the file system

How many files it can store

Where to find free space on the file system Other information

Page 14: Ch2

File System: Inode List

Inodes are used to access disk files.Inodes maps the disk filesFor each file there is an inode entry in the

inode list blockInode list also keeps track of directory

structure

Page 15: Ch2

File System: Data Block

Starts at the end of the inode listContains disk filesAn allocated data block can belong to one

and only one file in the file system

Page 16: Ch2

Processes(1)A process is the execution of a program A process is consists of text (machine code),

data and stackMany process can run simultaneously as kernel

schedules them for executionSeveral processes may be instances of one

programA process reads and writes its data and stack

sections, but it cannot read or write the data and stack of other processes

A process communicates with other processes and the rest of the world via system calls

Page 17: Ch2

Processes(2)

Kernel has a process table that keeps tract of all active processes

Each entry in the process table contains pointers to the text, data, stack and the U Area of a process.

All processes in UNIX system, except the very first process (process 0) which is created by the system boot code, are created by the fork system call

Page 18: Ch2

Kernel Support for Process

Text

Stack

DataFile Descriptor Table

Per Process Region Table

Kernel Process Table

Kernel Region TableA Process

U Area

Page 19: Ch2

Process: Region Table

Region table entries describes the attributes of the region, such as whether it contains text or data, whether it is shared or private

The extra level from the per process region table to kernel region table allows independent processes to share regions.

Page 20: Ch2

Process: U Area

U Area is the extension of process table entry.

Fields of process table entry: State field User ID (UID)

Fields of U Area Pointer to process table entry File descriptors of all open files Current directory and current root I/O parameters Process and file size limit

Kernel can directly access fields of the U Area of the executing process but not of the U Area of other processes

Page 21: Ch2

Process Context

The context of a process is its state: Text, data( variable), register Process region table, U Area, User stack and kernel stack

When executing a process, the system is said to be executing in the context of the process.

Page 22: Ch2

Context Switch

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

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.

Page 23: Ch2

Mode of Process Execution(1)

The UNIX process runs in two modes: User mode

Can access its own instructions and data, but not kernel instruction and data

Kernel mode Can access kernel and user instructions and data

When a process executes a system call, the execution mode of the process changes from user mode to kernel mode

Page 24: Ch2

Mode of Process Execution(2)

When moving from user to kernel mode, the kernel saves enough information so that it can later return to user mode and continue execution from where it left off.

Mode change is not a context switch, just change in mode.

Page 25: Ch2

Process States

Process states are: The process is running in user mode The process is running in kernel mode The process is not executing, but it is ready to run

as soon as the scheduler chooses it The process is sleeping

Such as waiting for I/O to complete

Page 26: Ch2

Process State Transition(1)

2

4

1

3asleep

user running

kernel running

ready to run

system call or interrupt

Interrupt return

schedule processsleep

wakeup

return

context switch permissible

Page 27: Ch2

Process State Transition(2)

The kernel allows a context switch only when a process moves from the state kernel running to the state asleep

Process running in kernel mode cannot be preempted by other processes.

Page 28: Ch2

Fork System Call(1)

When a process is created by fork, it contains duplicate copies of the text, data and stack segments of its parent

Also it has a File Descriptor Table (FDT) that contains references to the same opened files as its parent, such that they both share the same file pointer to each opened file

Page 29: Ch2

Fork System Call(2)

Parent

Child

U Area

U Area

stack

data

text

stack

data

Kernel File Table

Kernel RegionTable

Region table

Region table


Top Related