You are on page 1of 33

1.

Introduction to kernel

2.1 Block diagram of system kernel

2.2 Describe architecture of UNIX operating system


File subsystem
• Kernel’s file subsystem regulates data flow between
the kernel and secondary storage devices using buffering
mechanism.
• Where buffering mechanism interacts with the blocks I/O
device drivers to initiate data transfer to and from the
kernel.
• Device drivers are the kernel modules that controls the
Operation of peripheral devices.

3
Process Control Subsystem
• It is responsible for :
1. Process Synchronization
2. Interprocess communication
3. Memory management
4. Scheduler : process scheduling
(allocate CPU to Processes)

The file subsystem and process control


subsystem interacts when loading of a file
into memory for execution and process
systems reads executable files into memory
before executing them.
4
Hardware Control

• 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.
• The kernel may resume execution of the interrupted
process after servicing the interrupt.
Where interrupts are not serviced by special processes
but by special functions in the kernel known as context
of the currently running process.
5
Processes
•A process is created every time you run a UNIX command
or program from the command line.
•A program is an executable file.
• A process is an instance of the program in execution.
• A process has
 text: machine instructions
(may be shared by other processes)
 data
 stack

• Process may execute either in user mode and in kernel


mode.
• Process information are stored in two places:
 Process table 6
Text The text section contains the machine-
language code to be executed by the machine
on behalf of the process.
Data The data section contains a
representation of data preset to initial values.
It also includes the amount of space to be
allocated by the kernel for uninitialized data
(known for historic reasons as bss).
Stack The stack area usually contains
procedure-based, downward growing, data
frames.
User mode and Kernel mode
Kernel Mode:
•When CPU is in kernel mode, the code being executed can access any
memory address and any hardware resource.
•Hence kernel mode is a very privileged and powerful mode.
•If a program crashes in kernel mode, the entire system will be halted.
User Mode:
• When CPU is in user mode, the programs don’t have direct access to
memory and hardware resources.
• In user mode, if any program crashes, only that particular program is halted.
• That means the system will be in a safe state even if a program in user mode
crashes.
• Hence, most programs in an OS run in user mode.

8
Key Attributes of a UNIX Process

Each UNIX process has many attributes associated with it. The following list
contains some of the key attributes of a process:

 Process ID (PID) - a unique number assigned to the process when it is created.


The system and the process's owner use this number to manage the process.
 Parent Process ID (PPID) - the process ID of the process's parent.
 User ID (UID) - the user ID number of the user who started the process.
 Group ID (GID) - the group ID number of the user who started the process.
 TTY - the terminal device associated with the process.

9
10
11
User Table (u area)
• Each process has only one private user table.
• User table contains information that must be accessible
while the process is in execution.
 A pointer to the process table slot
 parameters of the current system call, return values
error codes
 file descriptors for all open files
 current directory and current root
 process and file size limits.
• User table is an extension of the process table.
12
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
Process Table
• Process table: an entry in process table has the following
information:
 process state:
A. running in user mode or kernel mode
B. Ready in memory or Ready but swapped
C. Sleep in memory or sleep and swapped
 PID: process id
 UID: user id
 scheduling information
 signals that is sent to the process but not yet handled
 a pointer to per-process-region table
• There is a single process table for the entire system

14
Process Region
table table
text
data
stack

Active process

Reference
text count = 2
data
stack
Per-process
region table 15
Introduction to system concepts

1. File Subsystem
2. Process control subsystem
3. Kernel data structures
File subsystem

How file system is created and stored?

Parts of file subsystem

Boot Super Inode List Data Blocks


Block Block
For file accessing mechanism ,kernel has 2 data structures

a) File table
b) User file descriptor table
Process

Concept of a process
-In Unix f first process created when system boots is process0.
-Which then uses fork() system call to create process 1 called as init
process
-Then this process 0 converts itself into just swapper process
-Now process 1 takes charge of all system and has special
relationship with its child…sub child, sub-sub-child…etc.
-Init process becomes most ancestor process for all other processes.

The executable program contains following things


1) A set of headers ,which will describer attributes of this file
2) the machine instruction form of our code.
3) The machine language representation of programs data
4) other sections like symbol table etc.
What is the content of process?

Whenever we execute a program from command prompt kernel load that program in to
RAM and now called as process

Regions of process

1) Text

The machine language code of your program’s code


2) Data

Memory blocks reserved for both initialized and uninitialized global data
3) Stack

it contains frames for function call in program (user stack)


and contains frames for each system call that have made during execution of program
(kernel stack)
Data of frame includes

- Local variables
- Address of previous frame
- return address of the call
- parameters of function

Registers used for stack management

1) Stack pointer (points to the top of the stack)


2) Program counter

How there is switch between user mode and kernel mode?


Data structure of process
1) U area

Contents of u area are


- A pointer to the process table slot of currently running process
- Parameters of the current system call, return value of current system call and error codes
of current system call
- File descriptor for all open files
- Internal I/O parameters
- Current directory and current root
- Process size limit and file size limit

2) Process Table

It contains entries for all running processes in the system

Content of each such entry in process table

- This table contains pointer to “per-process region table”


- A static field
- Identifiers of all users who owning this process
- An “event descriptor set” if a running process is suspended in sleep state.
3) Per-process Region table

This contains the “pointer to region table”

4) Region table

Region table is array of process’s address space. An entry of a process in region


table tells kernel many things like

- whether process contains text or data?


- process is private or shared?
- Where the data of the process is located in RAM?

Why per process region table is necessary?


Context of process

It is package of process related information .its content are

-State of process
-Values of global variables in the process
- Values of CPU registers that are used by process
-Values in its process table slot
-Its u area
-Contents of its user stack
-Contents of its kernel stack

Context switch

How context switch can be performed by kernel?


Process states
1) Process is Running in user mode
2) Process is Running in kernel mode
3) Process is Ready to run
4) The process is sleeping
Process state transition
What is interrupt ?

while handling the interrupts, Kernel gives first preference to high


priority interrupts and then t o low priority interrupts
Processor execution levels.
We can set processor execution level to one of the level, so that the
leveled interrupt and the lower set level are bypassed and only high
priority levels are taken into consideration.

This type of processor execution level setting is necessary ,particularly


for 2 case…

1) During the critical activity: ex. linked list


2) Privileged instructions: Some instruction is process are so important
that they must be dealt first.
How can kernel data structure gets corrupted during context switch?

How it can avoided by kernel?

-> for interrupts raising processor execution level


-> for processes using sleep and wakeup
Sleep and wakeup

sleep(event):

Allows process to sleep till an event occurs.

Wakeup()

Wakeups the process after event occurs.


For sleep
While (lock condition is true)
{

sleep(event: the condition become false );

}
Again set condition true;

For wakeup
Set condition to false
Wakeup(event: the condition becomes false)
Kernel data structures

The global data structures of kernel are usually “tables”(arrays ) of fixed size
rather than dynamic allocated size.

You might also like