SlideShare a Scribd company logo
Operating System and Administration
UNIT-II
Introduction To The Kernel
Reference:
“ The Design of the UNIX Operating
System”, by Maurice J. Bach.
17/05/2024 1
Objectives
• To understand system kernel architecture.
• To understand files subsystem and process control
subsystem of kernel.
• To learn and understand Process states and
contexts.
17/05/2024 2
Contents
• Architecture of Unix Operating System
• Introduction to the System Concepts
– An overview of the file subsystem
– Processes
• Context of a process
• Process states
• State transitions
• Sleep and wakeup
• Kernel Data Structure
• System Administration
17/05/2024 3
What is Kernel
• It acts as an interface between the user
applications and the hardware.
• The main tasks of the kernel
are:
– Process management
– Device management
– Memory management
– Interrupt handling
– I/O communication
– File system...etc..
17/05/2024 4
Contents
• Architecture of Unix Operating System
17/05/2024 5
• Introduction to the System Concepts
– An overview of the file subsystem
– Processes
• Context of a process
• Process states
• State transitions
• Sleep and wakeup
• Kernel Data Structure
• System Administration
Architecture of the UNIX
• Unix system supports two central concepts
– File system : has “Places”
(basic unit of information storage)
– - Processes : have “life”
– (basic unit of computation)
17/05/2024 6
7
Block Diagram of System Kernel
Libraries
System Call Interface
File Subsystem
Process
Control
Subsystem
Inter-process
Communication
Scheduler
Memory
Management
Hardware Control
Hardware
Buffer Cache
Device Drivers
Character Block
User Level
Kernel
Level
Kernel Level
Hardware Level
Trap
User Programs
17/05/2024
8
System calls & Libraries
Libraries
System Call Interface
File Subsystem
Process
Control
Subsystem
Inter-process
Communication
Scheduler
Memory
Management
Hardware Control
Hardware
Buffer Cache
Device Drivers
Character Block
User Level
Kernel
Level
Kernel Level
Hardware Level
Trap
User Programs
17/05/2024
System calls & Libraries
• System call library
– System calls in user programs looks like normal C function.
– Then libraries maps them to primitives requires to enter in OS.
• Standard library
– User program uses libraries such as standard I/O .
– Linked with the programs at compile time and are part of the
user program
17/05/2024 9
System calls & Libraries
• System calls interacts with file subsystem
– Managing files and structures of file system
– Allocating file space
– Administering free space
– Controlling access to files
– Retrieving data for users
• System calls for process to interact with file subsystem
– open (to open file for reading/writing) & close
– read & write
– stat (to query the attributes of file)
– chown ( to change the record of who owns the file)
– chmod (to change access permissions of a file)
17/05/2024 10
11
File Subsystem
Libraries
System Call Interface
File Subsystem
Process
Control
Subsystem
Inter-process
Communication
Scheduler
Memory
Management
Hardware Control
Hardware
Buffer Cache
Device Drivers
Character Block
User Level
Kernel
Level
Kernel Level
Hardware Level
Trap
User Programs
17/05/2024
12
Buffering Mechanism
Libraries
System Call Interface
File Subsystem
Process
Control
Subsystem
Inter-process
Communication
Scheduler
Memory
Management
Hardware Control
Hardware
Buffer Cache
Device Drivers
Character Block
User Level
Kernel
Level
Kernel Level
Hardware Level
Trap
User Programs
17/05/2024
13
Buffering Mechanism (Cont..)
• Interact with block I/O device drivers to initiate
data transfer to and from kernel.
• Device drivers are the kernel modules that controls
operations of peripheral devices.
• Block I/O devices are random access storage
devices.
– Such as Tape unit,
– hard disk,
– USB cameras etc.
17/05/2024
• File subsystem also interacts with “raw” I/O
device drivers without buffering mechanism.
• Raw devices also called as character devices.
– Such as serial port,
– parallel port,
– sound cards, etc.
17/05/2024 14
File Subsystem
15
Process Control Subsystem
Libraries
System Call Interface
File Subsystem
Process
Control
Subsystem
Inter-process
Communication
Scheduler
Memory
Management
Hardware Control
Hardware
Buffer Cache
Device Drivers
Character Block
User Level
Kernel
Level
Kernel Level
Hardware Level
Trap
User Programs
17/05/2024
16
Process Control Subsystem (Cont..)
• Responsible for process synchronization
• Inter-process communication (IPC)
• Memory management
• Process scheduling
• Communicate with file subsystem
– Loading a file into memory for execution
• Interact with set of system calls
– fork (to create new process)
– exec (to overlay image of program onto running process)
– exit (to finish executing process)
– wait (synchronize process execution with exit of previously forked process)
– brk (to control size of memory allocated to a process)
– signal (to control process response to extraordinary events)
17/05/2024
17
Process Control Subsystem (Cont..)
• Memory management module
– Control the allocation of memory to a process
– In absence of enough memory kernel moves processes between main mem. &
sec. mem.
– Memory management is done with swapping & demand paging
• Scheduler module
– Allocate the CPU to processes
• Interprocess communication
– There are several forms.
• Asynchronous signaling of events
• Synchronous transmission of messages between processes.
17/05/2024
18
Hardware Control
Libraries
System Call Interface
File Subsystem
Process
Control
Subsystem
Inter-process
Communication
Scheduler
Memory
Management
Hardware Control
Hardware
Buffer Cache
Device Drivers
Character Block
User Level
Kernel
Level
Kernel Level
Hardware Level
Trap
User Programs
17/05/2024
19
Hardware Control (Cont..)
• 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, kernel may resume execution of interrupted
process after servicing the interrupt.
17/05/2024
Contents
• Architecture of Unix Operating System
• Introduction to the System Concepts
– An overview of the file subsystem
– Processes
• Context of a process
• Process states
• State transitions
• Sleep and wakeup
• Kernel Data Structure
• System Administration
17/05/2024 20
17/05/2024
Files
• What is file?
– A container for data with name
• contiguous / non-contiguous storage
• Types of files
21
Overview of File Subsystem
• Each file on disk has an associated data structure
in the operating system, called an "inode"
17/05/2024 22
Inode Structure
17/05/2024 23
• Several file names may be associated with a
single inode, but each file is controlled by
exactly ONE inode.
• ls –i (to get inode number)
• $ ls -li /tmp/a /home/bob/xfile /var/tmp/file
114693 -rw-r-r- 3 hjc hjc 5 Sep 6 13:55 /tmp/a
114693 -rw-r-r- 3 hjc hjc 5 Sep 6 13:55 /home/bob/xfile
114693 -rw-r-r- 3 hjc hjc 5 Sep 6 13:55 /var/tmp/file
17/05/2024 24
Overview of File Subsystem (cont..)
Inode
no.
Permissions Link count Owner/group size Time Stamp
Finding a file’s Inode on Disk
17/05/2024 25
Example
• when a user issues open(``/etc/passwd'', ...) the
kernel performs the following operations:
– kernel finds the inode of the root directory and search the
corresponding file for the entry ``etc''
• when the entry ``etc'' is found, fetch its corresponding inode and check
that it is of type directory
– scan the file associated with ``/etc'' looking for ``passwd'‘
– finally, fetch the inode associated with passwd's directory entry,
verify that it is a regular file, and start accessing the file.
17/05/2024 26
• Inode Table
– List of all I-nodes
• Global File table
– It is global to the kernel
– It keeps track of the byte offset in the file where the user's next read/write
will start .
– It also keeps track of the access rights allowed to the opening process.
• User/Process File Descriptor table
– local to every process
– contains information like the identifiers of the files opened by the process.
– Whenever, a process creates / open a file, it gets an index from this table
called as ”File Descriptor”.
Data Structure for File Access
17/05/2024 27
User File
Descriptor Table
File
Table
Inode
Table
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);
17/05/2024 28
File Descriptors, File Table and Inode
table
17/05/2024 29
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.
17/05/2024 30
File System
17/05/2024 31
Physical Drive
Files and Directories Partitions
File System
• A file system is consists of a sequence of logical blocks
(512/1024 byte etc.)
17/05/2024 32
partition partition partition
disk drive
file system
super
block
boot
block
I-list
Data blocks for files, dirs, etc.
. . . . . . . .
.
i-node i-node i-node i-node
File System: Boot Block
• Typically occupies the first sector of the
disk
• Holds boot program, a short program for
loading the kernel of OS and launching it
17/05/2024 33
File System: Super Block
• Contains information about the geometry of the
physical disk
• Describes the state of a file system
• Describes the size of the file system
• a chain of free data block numbers
• a chain of free i-node numbers
17/05/2024 34
File System: Inode List
• Inodes are used to access disk files.
• Inodes maps the disk files
• For each file there is an inode entry in the inode
list block
• Inode list also keeps track of directory structure
17/05/2024 35
File System: Data Block
• Starts at the end of the inode list
• Contains disk files (Data)
• An allocated data block can belong to one and
only one file in the file system
17/05/2024 36
Contents
• Architecture of Unix Operating System
• Introduction to the System Concepts
– An overview of the file subsystem
– Processes
• Context of a process
• Process states
• State transitions
• Sleep and wakeup
• Kernel Data Structure
• System Administration
17/05/2024 37
Processes
• A process is the execution of a program
• A process is consists
– object code (program) to be executed
– data which the process works on
– Stack
– Required resources
17/05/2024 38
Code Data
Status
Resource R0
Resource R1
Resource RN
Abstract Machine Environment (OS)
Process Pk
• Many process can run simultaneously as kernel schedules
them for execution
• Several processes may be instances of one program
• A 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 all processes in UNIX
system are created by the fork system call, except the very
first process (process 0) which is created by the system
boot code
17/05/2024 39
Processes (Cont..)
Process (Cont..)
17/05/2024 40
• Kernel loads an executable file into memory
during ‘exec’ system call’
• Loaded process consist of text, data, & stack.
• Stack consist of logical stack frames
• Stack Frame has
– Local variables, address of previous frame, return address, parameters to
function
#include <fcntl.h>
char buffer[2048];
int version ™ 1;
main(argc, argv)
int argc;
char *argv[];
{
int fdold, fdnew;
if (argc !=- 3)
{ printfC'need 2 arguments for copy programn");
exit(l);
}
fdold =- open(argv[l], O_RDONLY);
/* open source file read only */
if (fdold 1)
{ printf ("cannot open file %sn", argv[l]);
exit(l);
}
fdnew - creat(argv[2], 0666); /* create target file rw for all */
if (fdnew -- -1) { printf ("cannot create file %sn", argv[2]); exit(1);}
copy(fdold, fdnew);
exit(l);
}
41
Processes (Cont..)
copy (old, new)
int old, new;
{
int count;
while ((count - readfold, buffer, sizeof(buffer))) >
0)
write (new, buffer, count);
}
17/05/2024
17/05/2024 42
Processes (Cont..)
Addr of Frame 2
Ret addr after write call
Local
Vars
not
shown
params to
write
new buffer
count
Addr of Frame 1
Ret addr after copy call
Local
Vars
count
params to
copy
old
new
Addr of Frame 0
Ret addr after main call
Local
Vars
fdold
fdnew
params to
main
argc
argv
user stack
Addr of Frame 1
Ret addr after func2 call
Local
Vars
parms to kernel func2
Addr of Frame 0
Ret addr after func1 call
Local
Vars
params to kernel
func1
kernel stack
frame 3
call write()
frame 2
call copy()
frame 1
call main()
frame 3
frame 2
call func2()
frame 1
call func1()
frame 0 start frame 0 system call
interface
Direction of
stack growth
Processes (Cont..)
• Kernel has a process table that keeps track of
all active processes
• Process table contains a per process region
table whose entry points to entries in region
table.
17/05/2024 43
Data Structures for Process
17/05/2024 44
u area
main memory
region table
per process
region table
process table
• Fields of process table entry:
– State field
– User ID (UID)- owner of process
– An event descriptor set when a process is suspended
• u pointer (address)
17/05/2024 45
Process: Process Table
User
Process: Region Table
• A region is a contiguous area of a process’s
address space such as
– text, data and stack.
• Region table entries describes the attributes of
the region, such as
– whether it contains text or data,
– whether it is shared or private and
– Where the “data” of region is located in memory
17/05/2024 46
Process: U Area
• U Area is the extension of process table entry
• Fields of U Area
– Pointer to process table entry of currently executing process
– Parameters of the current system call, return values and error
codes.
– 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
17/05/2024 47
Contents
• Architecture of Unix Operating System
• Introduction to the System Concepts
– An overview of the file subsystem
– Processes
• Context of a process
• Process states
• State transitions
• Sleep and wakeup
• Kernel Data Structure
• System Administration
17/05/2024 48
Process Context
• The context of a process is its state, which is
defined by
– Its text,
– Values of global user variables, data structures, and
machine registers
– Values stored in Process table and U Area
– Contents of user and kernel stack
• When executing a process, the system is said to
be executing in the context of the process.
17/05/2024 49
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.
17/05/2024 50
Mode of Process Execution
• 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
• requires special instruction sequence to change from user
to kernel mode
• When a process executes a system call, the
execution mode of the process changes from
user mode to kernel mode
17/05/2024 51
Mode of Process Execution (cont..)
• 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.
17/05/2024 52
Contents
• Architecture of Unix Operating System
• Introduction to the System Concepts
– An overview of the file subsystem
– Processes
• Context of a process
• Process states and State transitions
• Sleep and wakeup
• Kernel Data Structure
• System Administration
17/05/2024 53
Process States
• Lifetime of process can be divided into a set
of states.
• Process states are:
– User mode: currently executing
– Kernel mode: currently executing
– Ready to run : soon as the scheduler chooses it
– Sleeping : waiting for I/O to complete.
17/05/2024 54
Process State Transition
17/05/2024 55
1
2
4 3
kernel
running
user
running
context switch
permissible
ready to run
return
sys call
or interrupt
interrupt,
interrupt return
schedule
process
sleep
wakeup
Process State Transition(cont..)
• 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.
• Kernel maintains consistency of its data
structures because it is non-preemptive, uses
mutual exclusion to restrict critical section.
17/05/2024 56
Example
struct queue {
} *bp, *bpl;
bpl—>forp — bp—>forp;
bpl—>backp — bp;
bp—>forp — bpl;
/* consider possible context switch here */
bp 1—>forp— >backp ~ bpl;
• Unix prevents such situation by disallowing
context switching when process is in kernel mode.
17/05/2024 57
Contents
• Architecture of Unix Operating System
• Introduction to the System Concepts
– An overview of the file subsystem
– Processes
• Context of a process
• Process states and State transitions
• Sleep and wakeup
• Kernel Data Structure
• System Administration
17/05/2024 58
Sleep and wakeup
• Process go to sleep when awaiting to happen some
event such as
– Waiting for I/O completion
– Waiting for process to exit
– Waiting for system resources to become available
– And so on
• When event occurs all sleeping process on that
event get wake up and enter in “ready to run” state
• Sleeping processes do not consume CPU resources
17/05/2024 59
Sleep and wakeup (cont..)
• Locks
– used to lock some shared data structures and other resources.
• Implementation of lock
while(condition is true)
sleep(event: condition becomes false);
set condition true;
• When event occur unlock the lock and awakens all
processes asleep on lock.
set condition false;
wakeup(event: condition is false);
• Consider processes A, B and C contended for a locked
buffer.
17/05/2024 60
17/05/2024 61
Kernel Data Structures
• Fixed size tables
– Advantage: Kernel code is simple
– Disadvantage: Limits no. of entries in table
– If table size exceeds kernel should report error to
user.
• Dynamic allocation
– Excess table space is wasted
• For simplicity of kernel algorithms Fixed size
tables are used.
17/05/2024 62
System Administration
• Administrative Processes are used to perform various functions for
general welfare of user community.
– Disk formatting
– Creation of new file systems
– Repair of damaged file systems
– Kernel debugging, etc…
• Administrative processes are distinguished in terms of rights and
privileges provided to them.
– Eg. File access permissions allows manipulation to administrative process not
to user process.
• Superuser
– has special privileges.
– User may become superuser by using login-password.
17/05/2024 63
Exercise
• Assignment 1:
What should happen if the kernel attempts to awaken all processes
sleeping on an event, but no process are asleep on the event at the
time of the wakeup?
• No process is waken up.
– If scheduler finds at least one process in the queue, everything goes on.
– If not, no process will be scheduled, and kernel will not have anything to do so it
will not do anything. It will be idle.
– Then how would the kernel know, if it is idle, that some process wants it to do
something?
– Well, the answer is, scheduler comes a checks the ready to run queue on
every/some clock interrupts.
17/05/2024 64
Exercise
• Assignment 2:
Consider the following sequence of commands:
Case 1: grep main a.c b.c c.c > grepout &
wc —1 < grepout &
rm grepout &
The ampersand ("&") at the end of each command line informs the
shell to run the command in the background, and it can execute
each command line in parallel. Why is this not equivalent to the
following command line?
Case 2: grep main a.c b.c c.c | wc —1
17/05/2024 65
Excercise
• Assignment 3:
struct queue { } *bp, *bpl;
bp1—>forp = bp—>forp;
bp1—>backp = bp;
bp—>forp = bp1;
/* consider possible context switch here, and scheduled
process executes remove() function */
void remove(struct queue *qp)
{
qp—>forp —>backp = qp—>backp;
qp—>backp —>forp = qp—>forp;
qp—>forp = qp—>backp = NULL;
}
/*Return from context switch to execute remaining
code*/
bp1—>forp— >backp = bp1;
17/05/2024 66
So what is the status of the
link list if
case 1: qp = bp;
case 2: qp = bp1;
case 3: qp = Node that follows
bp in original Link List i.e.
before adding bp1.
67
17/05/2024

More Related Content

Similar to Unit 2.1 Introduction to Kernel.ppt (Kernel Services and Architecture)

Ioppt
IopptIoppt
5263802.ppt
5263802.ppt5263802.ppt
File Management in Operating Systems
File Management in Operating SystemsFile Management in Operating Systems
File Management in Operating Systems
vampugani
 
MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptx
ManasaPJ1
 
File System operating system operating system
File System  operating system operating systemFile System  operating system operating system
File System operating system operating system
Ethiopia Satlliet television
 
Presentation on nfs,afs,vfs
Presentation on nfs,afs,vfsPresentation on nfs,afs,vfs
Presentation on nfs,afs,vfs
Prakriti Dubey
 
Linux 4 you
Linux 4 youLinux 4 you
Linux 4 you
Shashwat Shriparv
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
Nishant Munjal
 
LinuxTraining_26_Sept_2021.ppt
LinuxTraining_26_Sept_2021.pptLinuxTraining_26_Sept_2021.ppt
LinuxTraining_26_Sept_2021.ppt
muraridesai2
 
O svv92014
O svv92014O svv92014
UNIT I.pptx
UNIT I.pptxUNIT I.pptx
UNIT I.pptx
YogapriyaJ1
 
Unit 7
Unit 7Unit 7
Unit 7
siddr
 
File
FileFile
File
Mohd Arif
 
Unix File System
Unix File SystemUnix File System
Unix File System
student(MCA)
 
Introduction to char device driver
Introduction to char device driverIntroduction to char device driver
Introduction to char device driver
Vandana Salve
 
App A
App AApp A
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
Ganesh Naik
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
nullowaspmumbai
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems
Ahmed El-Arabawy
 
9781111306366 ppt ch11
9781111306366 ppt ch119781111306366 ppt ch11
9781111306366 ppt ch11
Dr. Ahmed Al Zaidy
 

Similar to Unit 2.1 Introduction to Kernel.ppt (Kernel Services and Architecture) (20)

Ioppt
IopptIoppt
Ioppt
 
5263802.ppt
5263802.ppt5263802.ppt
5263802.ppt
 
File Management in Operating Systems
File Management in Operating SystemsFile Management in Operating Systems
File Management in Operating Systems
 
MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptx
 
File System operating system operating system
File System  operating system operating systemFile System  operating system operating system
File System operating system operating system
 
Presentation on nfs,afs,vfs
Presentation on nfs,afs,vfsPresentation on nfs,afs,vfs
Presentation on nfs,afs,vfs
 
Linux 4 you
Linux 4 youLinux 4 you
Linux 4 you
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
LinuxTraining_26_Sept_2021.ppt
LinuxTraining_26_Sept_2021.pptLinuxTraining_26_Sept_2021.ppt
LinuxTraining_26_Sept_2021.ppt
 
O svv92014
O svv92014O svv92014
O svv92014
 
UNIT I.pptx
UNIT I.pptxUNIT I.pptx
UNIT I.pptx
 
Unit 7
Unit 7Unit 7
Unit 7
 
File
FileFile
File
 
Unix File System
Unix File SystemUnix File System
Unix File System
 
Introduction to char device driver
Introduction to char device driverIntroduction to char device driver
Introduction to char device driver
 
App A
App AApp A
App A
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems
 
9781111306366 ppt ch11
9781111306366 ppt ch119781111306366 ppt ch11
9781111306366 ppt ch11
 

More from AnilkumarBrahmane2

Unit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdfUnit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdf
AnilkumarBrahmane2
 
Unit 5.2 Device Driver.pdf (Device Driver)
Unit 5.2 Device Driver.pdf (Device Driver)Unit 5.2 Device Driver.pdf (Device Driver)
Unit 5.2 Device Driver.pdf (Device Driver)
AnilkumarBrahmane2
 
Unit 5.1 Memory Management_Device Driver_IPC.ppt
Unit 5.1 Memory Management_Device Driver_IPC.pptUnit 5.1 Memory Management_Device Driver_IPC.ppt
Unit 5.1 Memory Management_Device Driver_IPC.ppt
AnilkumarBrahmane2
 
Unit 4 File Management System.ppt (File Services)
Unit 4 File Management System.ppt (File Services)Unit 4 File Management System.ppt (File Services)
Unit 4 File Management System.ppt (File Services)
AnilkumarBrahmane2
 
Unit 3.2 Process Control.ppt (Process Control and Scheduling)
Unit 3.2 Process Control.ppt (Process Control and Scheduling)Unit 3.2 Process Control.ppt (Process Control and Scheduling)
Unit 3.2 Process Control.ppt (Process Control and Scheduling)
AnilkumarBrahmane2
 
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.pptUnit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
AnilkumarBrahmane2
 
Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)
Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)
Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)
AnilkumarBrahmane2
 
Unit 1 Introduction to Operating System.ppt
Unit 1 Introduction to Operating System.pptUnit 1 Introduction to Operating System.ppt
Unit 1 Introduction to Operating System.ppt
AnilkumarBrahmane2
 

More from AnilkumarBrahmane2 (8)

Unit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdfUnit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdf
 
Unit 5.2 Device Driver.pdf (Device Driver)
Unit 5.2 Device Driver.pdf (Device Driver)Unit 5.2 Device Driver.pdf (Device Driver)
Unit 5.2 Device Driver.pdf (Device Driver)
 
Unit 5.1 Memory Management_Device Driver_IPC.ppt
Unit 5.1 Memory Management_Device Driver_IPC.pptUnit 5.1 Memory Management_Device Driver_IPC.ppt
Unit 5.1 Memory Management_Device Driver_IPC.ppt
 
Unit 4 File Management System.ppt (File Services)
Unit 4 File Management System.ppt (File Services)Unit 4 File Management System.ppt (File Services)
Unit 4 File Management System.ppt (File Services)
 
Unit 3.2 Process Control.ppt (Process Control and Scheduling)
Unit 3.2 Process Control.ppt (Process Control and Scheduling)Unit 3.2 Process Control.ppt (Process Control and Scheduling)
Unit 3.2 Process Control.ppt (Process Control and Scheduling)
 
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.pptUnit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
 
Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)
Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)
Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)
 
Unit 1 Introduction to Operating System.ppt
Unit 1 Introduction to Operating System.pptUnit 1 Introduction to Operating System.ppt
Unit 1 Introduction to Operating System.ppt
 

Recently uploaded

Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 

Recently uploaded (20)

Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 

Unit 2.1 Introduction to Kernel.ppt (Kernel Services and Architecture)

  • 1. Operating System and Administration UNIT-II Introduction To The Kernel Reference: “ The Design of the UNIX Operating System”, by Maurice J. Bach. 17/05/2024 1
  • 2. Objectives • To understand system kernel architecture. • To understand files subsystem and process control subsystem of kernel. • To learn and understand Process states and contexts. 17/05/2024 2
  • 3. Contents • Architecture of Unix Operating System • Introduction to the System Concepts – An overview of the file subsystem – Processes • Context of a process • Process states • State transitions • Sleep and wakeup • Kernel Data Structure • System Administration 17/05/2024 3
  • 4. What is Kernel • It acts as an interface between the user applications and the hardware. • The main tasks of the kernel are: – Process management – Device management – Memory management – Interrupt handling – I/O communication – File system...etc.. 17/05/2024 4
  • 5. Contents • Architecture of Unix Operating System 17/05/2024 5 • Introduction to the System Concepts – An overview of the file subsystem – Processes • Context of a process • Process states • State transitions • Sleep and wakeup • Kernel Data Structure • System Administration
  • 6. Architecture of the UNIX • Unix system supports two central concepts – File system : has “Places” (basic unit of information storage) – - Processes : have “life” – (basic unit of computation) 17/05/2024 6
  • 7. 7 Block Diagram of System Kernel Libraries System Call Interface File Subsystem Process Control Subsystem Inter-process Communication Scheduler Memory Management Hardware Control Hardware Buffer Cache Device Drivers Character Block User Level Kernel Level Kernel Level Hardware Level Trap User Programs 17/05/2024
  • 8. 8 System calls & Libraries Libraries System Call Interface File Subsystem Process Control Subsystem Inter-process Communication Scheduler Memory Management Hardware Control Hardware Buffer Cache Device Drivers Character Block User Level Kernel Level Kernel Level Hardware Level Trap User Programs 17/05/2024
  • 9. System calls & Libraries • System call library – System calls in user programs looks like normal C function. – Then libraries maps them to primitives requires to enter in OS. • Standard library – User program uses libraries such as standard I/O . – Linked with the programs at compile time and are part of the user program 17/05/2024 9
  • 10. System calls & Libraries • System calls interacts with file subsystem – Managing files and structures of file system – Allocating file space – Administering free space – Controlling access to files – Retrieving data for users • System calls for process to interact with file subsystem – open (to open file for reading/writing) & close – read & write – stat (to query the attributes of file) – chown ( to change the record of who owns the file) – chmod (to change access permissions of a file) 17/05/2024 10
  • 11. 11 File Subsystem Libraries System Call Interface File Subsystem Process Control Subsystem Inter-process Communication Scheduler Memory Management Hardware Control Hardware Buffer Cache Device Drivers Character Block User Level Kernel Level Kernel Level Hardware Level Trap User Programs 17/05/2024
  • 12. 12 Buffering Mechanism Libraries System Call Interface File Subsystem Process Control Subsystem Inter-process Communication Scheduler Memory Management Hardware Control Hardware Buffer Cache Device Drivers Character Block User Level Kernel Level Kernel Level Hardware Level Trap User Programs 17/05/2024
  • 13. 13 Buffering Mechanism (Cont..) • Interact with block I/O device drivers to initiate data transfer to and from kernel. • Device drivers are the kernel modules that controls operations of peripheral devices. • Block I/O devices are random access storage devices. – Such as Tape unit, – hard disk, – USB cameras etc. 17/05/2024
  • 14. • File subsystem also interacts with “raw” I/O device drivers without buffering mechanism. • Raw devices also called as character devices. – Such as serial port, – parallel port, – sound cards, etc. 17/05/2024 14 File Subsystem
  • 15. 15 Process Control Subsystem Libraries System Call Interface File Subsystem Process Control Subsystem Inter-process Communication Scheduler Memory Management Hardware Control Hardware Buffer Cache Device Drivers Character Block User Level Kernel Level Kernel Level Hardware Level Trap User Programs 17/05/2024
  • 16. 16 Process Control Subsystem (Cont..) • Responsible for process synchronization • Inter-process communication (IPC) • Memory management • Process scheduling • Communicate with file subsystem – Loading a file into memory for execution • Interact with set of system calls – fork (to create new process) – exec (to overlay image of program onto running process) – exit (to finish executing process) – wait (synchronize process execution with exit of previously forked process) – brk (to control size of memory allocated to a process) – signal (to control process response to extraordinary events) 17/05/2024
  • 17. 17 Process Control Subsystem (Cont..) • Memory management module – Control the allocation of memory to a process – In absence of enough memory kernel moves processes between main mem. & sec. mem. – Memory management is done with swapping & demand paging • Scheduler module – Allocate the CPU to processes • Interprocess communication – There are several forms. • Asynchronous signaling of events • Synchronous transmission of messages between processes. 17/05/2024
  • 18. 18 Hardware Control Libraries System Call Interface File Subsystem Process Control Subsystem Inter-process Communication Scheduler Memory Management Hardware Control Hardware Buffer Cache Device Drivers Character Block User Level Kernel Level Kernel Level Hardware Level Trap User Programs 17/05/2024
  • 19. 19 Hardware Control (Cont..) • 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, kernel may resume execution of interrupted process after servicing the interrupt. 17/05/2024
  • 20. Contents • Architecture of Unix Operating System • Introduction to the System Concepts – An overview of the file subsystem – Processes • Context of a process • Process states • State transitions • Sleep and wakeup • Kernel Data Structure • System Administration 17/05/2024 20
  • 21. 17/05/2024 Files • What is file? – A container for data with name • contiguous / non-contiguous storage • Types of files 21
  • 22. Overview of File Subsystem • Each file on disk has an associated data structure in the operating system, called an "inode" 17/05/2024 22
  • 24. • Several file names may be associated with a single inode, but each file is controlled by exactly ONE inode. • ls –i (to get inode number) • $ ls -li /tmp/a /home/bob/xfile /var/tmp/file 114693 -rw-r-r- 3 hjc hjc 5 Sep 6 13:55 /tmp/a 114693 -rw-r-r- 3 hjc hjc 5 Sep 6 13:55 /home/bob/xfile 114693 -rw-r-r- 3 hjc hjc 5 Sep 6 13:55 /var/tmp/file 17/05/2024 24 Overview of File Subsystem (cont..) Inode no. Permissions Link count Owner/group size Time Stamp
  • 25. Finding a file’s Inode on Disk 17/05/2024 25
  • 26. Example • when a user issues open(``/etc/passwd'', ...) the kernel performs the following operations: – kernel finds the inode of the root directory and search the corresponding file for the entry ``etc'' • when the entry ``etc'' is found, fetch its corresponding inode and check that it is of type directory – scan the file associated with ``/etc'' looking for ``passwd'‘ – finally, fetch the inode associated with passwd's directory entry, verify that it is a regular file, and start accessing the file. 17/05/2024 26
  • 27. • Inode Table – List of all I-nodes • Global File table – It is global to the kernel – It keeps track of the byte offset in the file where the user's next read/write will start . – It also keeps track of the access rights allowed to the opening process. • User/Process File Descriptor table – local to every process – contains information like the identifiers of the files opened by the process. – Whenever, a process creates / open a file, it gets an index from this table called as ”File Descriptor”. Data Structure for File Access 17/05/2024 27 User File Descriptor Table File Table Inode Table
  • 28. 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); 17/05/2024 28
  • 29. File Descriptors, File Table and Inode table 17/05/2024 29
  • 30. 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. 17/05/2024 30
  • 31. File System 17/05/2024 31 Physical Drive Files and Directories Partitions
  • 32. File System • A file system is consists of a sequence of logical blocks (512/1024 byte etc.) 17/05/2024 32 partition partition partition disk drive file system super block boot block I-list Data blocks for files, dirs, etc. . . . . . . . . . i-node i-node i-node i-node
  • 33. File System: Boot Block • Typically occupies the first sector of the disk • Holds boot program, a short program for loading the kernel of OS and launching it 17/05/2024 33
  • 34. File System: Super Block • Contains information about the geometry of the physical disk • Describes the state of a file system • Describes the size of the file system • a chain of free data block numbers • a chain of free i-node numbers 17/05/2024 34
  • 35. File System: Inode List • Inodes are used to access disk files. • Inodes maps the disk files • For each file there is an inode entry in the inode list block • Inode list also keeps track of directory structure 17/05/2024 35
  • 36. File System: Data Block • Starts at the end of the inode list • Contains disk files (Data) • An allocated data block can belong to one and only one file in the file system 17/05/2024 36
  • 37. Contents • Architecture of Unix Operating System • Introduction to the System Concepts – An overview of the file subsystem – Processes • Context of a process • Process states • State transitions • Sleep and wakeup • Kernel Data Structure • System Administration 17/05/2024 37
  • 38. Processes • A process is the execution of a program • A process is consists – object code (program) to be executed – data which the process works on – Stack – Required resources 17/05/2024 38 Code Data Status Resource R0 Resource R1 Resource RN Abstract Machine Environment (OS) Process Pk
  • 39. • Many process can run simultaneously as kernel schedules them for execution • Several processes may be instances of one program • A 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 all processes in UNIX system are created by the fork system call, except the very first process (process 0) which is created by the system boot code 17/05/2024 39 Processes (Cont..)
  • 40. Process (Cont..) 17/05/2024 40 • Kernel loads an executable file into memory during ‘exec’ system call’ • Loaded process consist of text, data, & stack. • Stack consist of logical stack frames • Stack Frame has – Local variables, address of previous frame, return address, parameters to function
  • 41. #include <fcntl.h> char buffer[2048]; int version ™ 1; main(argc, argv) int argc; char *argv[]; { int fdold, fdnew; if (argc !=- 3) { printfC'need 2 arguments for copy programn"); exit(l); } fdold =- open(argv[l], O_RDONLY); /* open source file read only */ if (fdold 1) { printf ("cannot open file %sn", argv[l]); exit(l); } fdnew - creat(argv[2], 0666); /* create target file rw for all */ if (fdnew -- -1) { printf ("cannot create file %sn", argv[2]); exit(1);} copy(fdold, fdnew); exit(l); } 41 Processes (Cont..) copy (old, new) int old, new; { int count; while ((count - readfold, buffer, sizeof(buffer))) > 0) write (new, buffer, count); } 17/05/2024
  • 42. 17/05/2024 42 Processes (Cont..) Addr of Frame 2 Ret addr after write call Local Vars not shown params to write new buffer count Addr of Frame 1 Ret addr after copy call Local Vars count params to copy old new Addr of Frame 0 Ret addr after main call Local Vars fdold fdnew params to main argc argv user stack Addr of Frame 1 Ret addr after func2 call Local Vars parms to kernel func2 Addr of Frame 0 Ret addr after func1 call Local Vars params to kernel func1 kernel stack frame 3 call write() frame 2 call copy() frame 1 call main() frame 3 frame 2 call func2() frame 1 call func1() frame 0 start frame 0 system call interface Direction of stack growth
  • 43. Processes (Cont..) • Kernel has a process table that keeps track of all active processes • Process table contains a per process region table whose entry points to entries in region table. 17/05/2024 43
  • 44. Data Structures for Process 17/05/2024 44 u area main memory region table per process region table process table
  • 45. • Fields of process table entry: – State field – User ID (UID)- owner of process – An event descriptor set when a process is suspended • u pointer (address) 17/05/2024 45 Process: Process Table User
  • 46. Process: Region Table • A region is a contiguous area of a process’s address space such as – text, data and stack. • Region table entries describes the attributes of the region, such as – whether it contains text or data, – whether it is shared or private and – Where the “data” of region is located in memory 17/05/2024 46
  • 47. Process: U Area • U Area is the extension of process table entry • Fields of U Area – Pointer to process table entry of currently executing process – Parameters of the current system call, return values and error codes. – 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 17/05/2024 47
  • 48. Contents • Architecture of Unix Operating System • Introduction to the System Concepts – An overview of the file subsystem – Processes • Context of a process • Process states • State transitions • Sleep and wakeup • Kernel Data Structure • System Administration 17/05/2024 48
  • 49. Process Context • The context of a process is its state, which is defined by – Its text, – Values of global user variables, data structures, and machine registers – Values stored in Process table and U Area – Contents of user and kernel stack • When executing a process, the system is said to be executing in the context of the process. 17/05/2024 49
  • 50. 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. 17/05/2024 50
  • 51. Mode of Process Execution • 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 • requires special instruction sequence to change from user to kernel mode • When a process executes a system call, the execution mode of the process changes from user mode to kernel mode 17/05/2024 51
  • 52. Mode of Process Execution (cont..) • 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. 17/05/2024 52
  • 53. Contents • Architecture of Unix Operating System • Introduction to the System Concepts – An overview of the file subsystem – Processes • Context of a process • Process states and State transitions • Sleep and wakeup • Kernel Data Structure • System Administration 17/05/2024 53
  • 54. Process States • Lifetime of process can be divided into a set of states. • Process states are: – User mode: currently executing – Kernel mode: currently executing – Ready to run : soon as the scheduler chooses it – Sleeping : waiting for I/O to complete. 17/05/2024 54
  • 55. Process State Transition 17/05/2024 55 1 2 4 3 kernel running user running context switch permissible ready to run return sys call or interrupt interrupt, interrupt return schedule process sleep wakeup
  • 56. Process State Transition(cont..) • 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. • Kernel maintains consistency of its data structures because it is non-preemptive, uses mutual exclusion to restrict critical section. 17/05/2024 56
  • 57. Example struct queue { } *bp, *bpl; bpl—>forp — bp—>forp; bpl—>backp — bp; bp—>forp — bpl; /* consider possible context switch here */ bp 1—>forp— >backp ~ bpl; • Unix prevents such situation by disallowing context switching when process is in kernel mode. 17/05/2024 57
  • 58. Contents • Architecture of Unix Operating System • Introduction to the System Concepts – An overview of the file subsystem – Processes • Context of a process • Process states and State transitions • Sleep and wakeup • Kernel Data Structure • System Administration 17/05/2024 58
  • 59. Sleep and wakeup • Process go to sleep when awaiting to happen some event such as – Waiting for I/O completion – Waiting for process to exit – Waiting for system resources to become available – And so on • When event occurs all sleeping process on that event get wake up and enter in “ready to run” state • Sleeping processes do not consume CPU resources 17/05/2024 59
  • 60. Sleep and wakeup (cont..) • Locks – used to lock some shared data structures and other resources. • Implementation of lock while(condition is true) sleep(event: condition becomes false); set condition true; • When event occur unlock the lock and awakens all processes asleep on lock. set condition false; wakeup(event: condition is false); • Consider processes A, B and C contended for a locked buffer. 17/05/2024 60
  • 62. Kernel Data Structures • Fixed size tables – Advantage: Kernel code is simple – Disadvantage: Limits no. of entries in table – If table size exceeds kernel should report error to user. • Dynamic allocation – Excess table space is wasted • For simplicity of kernel algorithms Fixed size tables are used. 17/05/2024 62
  • 63. System Administration • Administrative Processes are used to perform various functions for general welfare of user community. – Disk formatting – Creation of new file systems – Repair of damaged file systems – Kernel debugging, etc… • Administrative processes are distinguished in terms of rights and privileges provided to them. – Eg. File access permissions allows manipulation to administrative process not to user process. • Superuser – has special privileges. – User may become superuser by using login-password. 17/05/2024 63
  • 64. Exercise • Assignment 1: What should happen if the kernel attempts to awaken all processes sleeping on an event, but no process are asleep on the event at the time of the wakeup? • No process is waken up. – If scheduler finds at least one process in the queue, everything goes on. – If not, no process will be scheduled, and kernel will not have anything to do so it will not do anything. It will be idle. – Then how would the kernel know, if it is idle, that some process wants it to do something? – Well, the answer is, scheduler comes a checks the ready to run queue on every/some clock interrupts. 17/05/2024 64
  • 65. Exercise • Assignment 2: Consider the following sequence of commands: Case 1: grep main a.c b.c c.c > grepout & wc —1 < grepout & rm grepout & The ampersand ("&") at the end of each command line informs the shell to run the command in the background, and it can execute each command line in parallel. Why is this not equivalent to the following command line? Case 2: grep main a.c b.c c.c | wc —1 17/05/2024 65
  • 66. Excercise • Assignment 3: struct queue { } *bp, *bpl; bp1—>forp = bp—>forp; bp1—>backp = bp; bp—>forp = bp1; /* consider possible context switch here, and scheduled process executes remove() function */ void remove(struct queue *qp) { qp—>forp —>backp = qp—>backp; qp—>backp —>forp = qp—>forp; qp—>forp = qp—>backp = NULL; } /*Return from context switch to execute remaining code*/ bp1—>forp— >backp = bp1; 17/05/2024 66 So what is the status of the link list if case 1: qp = bp; case 2: qp = bp1; case 3: qp = Node that follows bp in original Link List i.e. before adding bp1.