What is Kernel
•Itactsasaninterfacebetweentheuser
applicationsandthehardware.
•Themaintasksofthekernel
are:
–Processmanagement
–Devicemanagement
–Memorymanagement
–Interrupthandling
–I/Ocommunication
–Filesystem...etc..
17/05/2024 4
Contents
•ArchitectureofUnixOperatingSystem
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
•Unixsystemsupportstwocentralconcepts
–Filesystem:has“Places”
(basicunitofinformationstorage)
– -Processes:have“life”
– (basicunitofcomputation)
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
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
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..)
•Responsibleforprocesssynchronization
•Inter-processcommunication(IPC)
•Memorymanagement
•Processscheduling
•Communicatewithfilesubsystem
–Loadingafileintomemoryforexecution
•Interactwithsetofsystemcalls
–fork(tocreatenewprocess)
–exec(tooverlayimageofprogramontorunningprocess)
–exit(tofinishexecutingprocess)
–wait(synchronizeprocessexecutionwithexitofpreviouslyforkedprocess)
–brk(tocontrolsizeofmemoryallocatedtoaprocess)
–signal(tocontrolprocessresponsetoextraordinaryevents)
17/05/2024
17
Process Control Subsystem (Cont..)
•Memorymanagementmodule
–Controltheallocationofmemorytoaprocess
–Inabsenceofenoughmemorykernelmovesprocessesbetweenmainmem.&
sec.mem.
–Memorymanagementisdonewithswapping&demandpaging
•Schedulermodule
–AllocatetheCPUtoprocesses
•Interprocesscommunication
–Thereareseveralforms.
•Asynchronoussignalingofevents
•Synchronoustransmissionofmessagesbetweenprocesses.
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
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-nodei-nodei-node i-node
File System: Boot Block
•Typicallyoccupiesthefirstsectorofthe
disk
•Holdsbootprogram,ashortprogramfor
loadingthekernelofOSandlaunchingit
17/05/2024 33
Processes
•Aprocessistheexecutionofaprogram
•Aprocessisconsists
–objectcode(program)tobeexecuted
–datawhichtheprocessworkson
–Stack
–Requiredresources
17/05/2024 38
Code Data
Status
Resource R
0
Resource R
1
Resource R
N
Abstract Machine Environment (OS)
Process P
k
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
Process States
•Lifetimeofprocesscanbedividedintoaset
ofstates.
•Processstatesare:
–Usermode:currentlyexecuting
–Kernelmode:currentlyexecuting
–Readytorun:soonastheschedulerchoosesit
–Sleeping:waitingforI/Otocomplete.
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
returnsys call
or interrupt
interrupt,
interrupt return
schedule
processsleep
wakeup
Process State Transition(cont..)
•Thekernelallowsacontextswitchonlywhena
processmovesfromthestatekernelrunningto
thestateasleep
•Processrunninginkernelmodecannotbe
preemptedbyotherprocesses.
•Kernelmaintainsconsistencyofitsdata
structuresbecauseitisnon-preemptive,uses
mutualexclusiontorestrictcriticalsection.
17/05/2024 56
Excercise
•Assignment3:
structqueue{ }*bp,*bpl;
bp1—>forp=bp—>forp;
bp1—>backp=bp;
bp—>forp=bp1;
/*considerpossiblecontextswitchhere,andscheduled
processexecutesremove()function*/
voidremove(structqueue*qp)
{
qp—>forp—>backp=qp—>backp;
qp—>backp—>forp=qp—>forp;
qp—>forp=qp—>backp=NULL;
}
/*Returnfromcontextswitchtoexecuteremaining
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.