SlideShare a Scribd company logo
1 of 17
Saving the Context of a Process
• The kernel saves the context of a process
whenever it pushes a new system context
layer.
• This happens when the system receives an
interrupt, when a process executes a system
call, or when the kernel does a context switch.
• This section considers each case in detail.
Interrupt, system call interface, context switch.
Interrupts and Exceptions:
• The system is responsible for handling interrupts,
whether they result from hardware (such as from the
clock or from peripheral devices), from a programmed
interrupt (execution of instructions designed to cause
“software interrupt”, or from exceptions (such as page
faults).
• If the CPU is executing at a lower processor execution
level than the level of the interrupt it accepts the
interrupt before decoding the next instruction and
raises the processor execution level, so that no other
interrupts of the level (or lower level) can happen
while it handles the current interrupt, preserving the
integrity of the kernel data structure.
The kernel handles the interrupt with the following
sequence of operations:
1. It saves the current register context of the executing
process and creates (pushes) a new context layer.
2. It determines the “source” or cause of the interrupt,
identifying the type of interrupt (such as clock or disk) and
the unit number of the interrupt, if applicable (such as
which disk drive caused the interrupt).
3.When the system receives an interrupt, it gets a number
from the machine that it uses as an offset into a table
known as interrupt vector.
4.The contents of interrupt vector vary from machine to
machine, but they usually contain the address of the
interrupt handler for the corresponding interrupt source,
and a way of finding a parameter for the interrupt handler.
For e.g. consider the interrupt handler
table (fig 9)
The kernel invokes the interrupt
handler.
• The kernel stack for the new context layer is
logically distinct from the kernel stack of the
previous context layer.
• Some implementations use the kernel stack of
the executing process to store the interrupt
handler stack frames, and other
implementations use a global interrupt stack to
store the frames for the interrupt handlers that
are guaranteed to return without switching
context.
The interrupt handler completes its
work and returns.
• The kernel executes a machine-specific sequence of
instructions that restores the register context and
kernel stack of the previous context layer, as they
existed at the time of the interrupt and then resumes
execution of the restored context layer.
• The behavior of the process may be affected by the
interrupt handler, since the interrupt handler may
have altered the global kernel data structures and
awakened sleeping process.
• Usually the process continues execution as if the
interrupt had never happened.
System call Interface:
• The System call is a normal function call.
• The usual calling sequence cannot change the mode of
a process from user to kernel.
• The C compiler uses a predefined library of functions
that have the names of the system calls, thus
resolving the system call references in the user
program.
• The library functions typically invoke an instruction
that changes the process execution mode to kernel
mode and causes the kernel to start executing code
for system calls.
Context Switch:
• The kernel permits a context switch under four
circumstances: (fig 1)
• 1) when a process puts itself to sleep,
• 2) when it exits,
• 3) when it returns from a system call to user mode
but is not the most eligible process to run, or
• 4) when it returns to user mode after the kernel
completes handling an interrupt but is not the most
eligible process to run.
• The kernel ensures integrity and consistency of internal data
structures by prohibiting arbitrary context switches.
• It makes sure that the state of its data structures is consistent
before it does a context switch:
• i.e. that all appropriate updates are done,
• that queues are properly linked,
• that appropriate locks are set to prevent intrusion by other
processes, that no data structures are left unnecessarily locked
and so on.
• For e.g. if the kernel allocates a buffer, reads a block in a file, and
goes to sleep waiting for I/O transmission from the disk to
complete, it keeps the buffer locked so that no other process can
tamper with the buffer.
• But if a process executes the link system call, the kernel releases
the lock of the first inode before locking the second inode to
avoid deadlock.
• The kernel must do a context switch at the conclusion of the exit
system call, because there is nothing else for it to do.
The procedure for a context switch is similar to the procedures for
handling interrupts and system calls, except that the kernel restores the
content layer of a different process instead of the previous context layer
of the same process.
Similarly, the choice of which process to schedule next is a policy
decision that does not affect the mechanics of the context switch.
From fig 16; the function save_context( ) saves information about the context of the
running process and returns the value1.
1.Among other pieces of information, the kernel saves the value of the current
program counter (in the function save_context( )) and the value 0, to be used later as
the return value in register 0 from save_context.
2.The kernel continues to execute in the context of the old process (A), picking
another process (B) to run and calling resume_context( ) to restore the new context
(of B).
3.After the new context is restored, the system is executing process B; the old
process (A) is no longer executing but leaves its saved context behind. (hence the
comment in the fig 16. “never gets here”).
4.Later, the kernel will again pick process A to run (except for exit case) when
another process does a context switch, as just described.
5.When process A’s context is restored, the kernel will set the program counter to
the value process A had previously saved in the function save_context, and it will
also place the value 0, saved for the return value, into register 0.
6.The kernel resumes execution of process A inside save_context even though it had
executed the code up to the call to resume_context before the context switch.
7.Finally, process A returns from the function save_context with the value 0 (in reg 0)
and resumes execution after the comment line “resuming process executes from
here”.
Saving context for abortive returns
• Situations arise when the kernel abort its current execution
sequence and immediately execute out of a previously saved
contest.
• Sleep and signals describe the circumstances when a process must
suddenly change its contest;
• 1.Explains the mechanisms for executing a previous contest.
• The algorithm to save a contest is setup and the algorithm to
restore the contest is longjmp
• 2.The method is identical to the function save context , except that
save context pushes a new context larger where as setjmp stores
the saved context in the u area and continues to execute in the old
context larger.
• 3.When the kernel wishes to resume the context it had saved in
setjmp ,if does a long.restoring its context from the u area and
returning a 1 from setjmp.
Copying data between system and
user address space
• A process executes in kernel mode or in user mode with no
overlap of modes.
• Many system calls move data between kernel and user space, such
as when copying system call parameters from user to kernel space
or when copying data fron I/O buffers in the read system call.
• Many machines allow the kernel to reference addresses in user
space directly.
• The kernel must ascertain, that the address being read or written
is accessible as if it had been executing in user mode;
• o Otherwise it could override the ordinary protection mechanisms
and inadvertently read or write addresses outside the user address
space (possibly kernel data structure).

More Related Content

What's hot

Windows process scheduling presentation
Windows process scheduling presentationWindows process scheduling presentation
Windows process scheduling presentationTalha Shaikh
 
Linux process management
Linux process managementLinux process management
Linux process managementRaghu nath
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process ConceptsMukesh Chinta
 
Real Time Operating System Concepts
Real Time Operating System ConceptsReal Time Operating System Concepts
Real Time Operating System ConceptsSanjiv Malik
 
RTOS MICRO CONTROLLER OPERATING SYSTEM-2
RTOS MICRO CONTROLLER OPERATING SYSTEM-2RTOS MICRO CONTROLLER OPERATING SYSTEM-2
RTOS MICRO CONTROLLER OPERATING SYSTEM-2JOLLUSUDARSHANREDDY
 
Processes and Threads in Windows Vista
Processes and Threads in Windows VistaProcesses and Threads in Windows Vista
Processes and Threads in Windows VistaTrinh Phuc Tho
 
My ppt @ bec doms on process management
My ppt @ bec doms on process managementMy ppt @ bec doms on process management
My ppt @ bec doms on process managementBabasab Patil
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithmBinal Parekh
 
A deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorA deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorZongYing Lyu
 
Implementation of Kernel API
Implementation of Kernel APIImplementation of Kernel API
Implementation of Kernel APIkhushi74
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process managementArnav Chowdhury
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPTQUONTRASOLUTIONS
 
Evaluating the performance and behaviour of rt xen
Evaluating the performance and behaviour of rt xenEvaluating the performance and behaviour of rt xen
Evaluating the performance and behaviour of rt xenijesajournal
 

What's hot (18)

Windows process scheduling presentation
Windows process scheduling presentationWindows process scheduling presentation
Windows process scheduling presentation
 
Linux process management
Linux process managementLinux process management
Linux process management
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Lecture 5 process concept
Lecture 5   process conceptLecture 5   process concept
Lecture 5 process concept
 
Real Time Operating System Concepts
Real Time Operating System ConceptsReal Time Operating System Concepts
Real Time Operating System Concepts
 
Unit iv: Deadlocks
Unit iv: DeadlocksUnit iv: Deadlocks
Unit iv: Deadlocks
 
Process scheduling linux
Process scheduling linuxProcess scheduling linux
Process scheduling linux
 
RTOS MICRO CONTROLLER OPERATING SYSTEM-2
RTOS MICRO CONTROLLER OPERATING SYSTEM-2RTOS MICRO CONTROLLER OPERATING SYSTEM-2
RTOS MICRO CONTROLLER OPERATING SYSTEM-2
 
Processes and Threads in Windows Vista
Processes and Threads in Windows VistaProcesses and Threads in Windows Vista
Processes and Threads in Windows Vista
 
My ppt @ bec doms on process management
My ppt @ bec doms on process managementMy ppt @ bec doms on process management
My ppt @ bec doms on process management
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
 
A deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processorA deep dive into energy efficient multi core processor
A deep dive into energy efficient multi core processor
 
Implementation of Kernel API
Implementation of Kernel APIImplementation of Kernel API
Implementation of Kernel API
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
 
Process
ProcessProcess
Process
 
Process threads operating system.
Process threads operating system.Process threads operating system.
Process threads operating system.
 
Evaluating the performance and behaviour of rt xen
Evaluating the performance and behaviour of rt xenEvaluating the performance and behaviour of rt xen
Evaluating the performance and behaviour of rt xen
 

Similar to Unit 5 ppt

embedded system CHAPTER four about design .pdf
embedded system CHAPTER four about design .pdfembedded system CHAPTER four about design .pdf
embedded system CHAPTER four about design .pdfabdulkerimaragaw936
 
Operating system Q/A
Operating system Q/AOperating system Q/A
Operating system Q/AAbdul Munam
 
Synchronization linux
Synchronization linuxSynchronization linux
Synchronization linuxSusant Sahani
 
Unix Shell and System Boot Process
Unix Shell and System Boot ProcessUnix Shell and System Boot Process
Unix Shell and System Boot ProcessArvind Krishnaa
 
Faster recovery from operating system failure & file cache missing
Faster recovery from operating system failure & file cache missingFaster recovery from operating system failure & file cache missing
Faster recovery from operating system failure & file cache missingAthambawa Jaleel
 
AOS Lab 1: Hello, Linux!
AOS Lab 1: Hello, Linux!AOS Lab 1: Hello, Linux!
AOS Lab 1: Hello, Linux!Zubair Nabi
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecturejeetesh036
 
Real Time Kernels
Real Time KernelsReal Time Kernels
Real Time KernelsArnav Soni
 
Cpu scheduling final
Cpu scheduling finalCpu scheduling final
Cpu scheduling finalmarangburu42
 
MODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxMODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxsenthilkumar969017
 
Engg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdfEngg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdfnikhil287188
 
Operating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdfOperating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdfFahanaAbdulVahab
 
Lecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfLecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfTaufeeq8
 
Cpu scheduling pre final formatting
Cpu scheduling pre final formattingCpu scheduling pre final formatting
Cpu scheduling pre final formattingmarangburu42
 

Similar to Unit 5 ppt (20)

embedded system CHAPTER four about design .pdf
embedded system CHAPTER four about design .pdfembedded system CHAPTER four about design .pdf
embedded system CHAPTER four about design .pdf
 
Operating system Q/A
Operating system Q/AOperating system Q/A
Operating system Q/A
 
UNIT II - CPU SCHEDULING.docx
UNIT II - CPU SCHEDULING.docxUNIT II - CPU SCHEDULING.docx
UNIT II - CPU SCHEDULING.docx
 
Synchronization linux
Synchronization linuxSynchronization linux
Synchronization linux
 
Seminar
SeminarSeminar
Seminar
 
Rtos
RtosRtos
Rtos
 
Unix Shell and System Boot Process
Unix Shell and System Boot ProcessUnix Shell and System Boot Process
Unix Shell and System Boot Process
 
Faster recovery from operating system failure & file cache missing
Faster recovery from operating system failure & file cache missingFaster recovery from operating system failure & file cache missing
Faster recovery from operating system failure & file cache missing
 
AOS Lab 1: Hello, Linux!
AOS Lab 1: Hello, Linux!AOS Lab 1: Hello, Linux!
AOS Lab 1: Hello, Linux!
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecture
 
Real Time Kernels
Real Time KernelsReal Time Kernels
Real Time Kernels
 
Cpu scheduling final
Cpu scheduling finalCpu scheduling final
Cpu scheduling final
 
MODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxMODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptx
 
Engg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdfEngg-0505-IT-Operating-Systems-2nd-year.pdf
Engg-0505-IT-Operating-Systems-2nd-year.pdf
 
Operating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdfOperating Systems PPT 1 (1).pdf
Operating Systems PPT 1 (1).pdf
 
Lecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdfLecture1,2,3 (1).pdf
Lecture1,2,3 (1).pdf
 
test1_361
test1_361test1_361
test1_361
 
Unit 2 notes
Unit 2 notesUnit 2 notes
Unit 2 notes
 
Cpu scheduling pre final formatting
Cpu scheduling pre final formattingCpu scheduling pre final formatting
Cpu scheduling pre final formatting
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 

Recently uploaded

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 

Unit 5 ppt

  • 1. Saving the Context of a Process • The kernel saves the context of a process whenever it pushes a new system context layer. • This happens when the system receives an interrupt, when a process executes a system call, or when the kernel does a context switch. • This section considers each case in detail. Interrupt, system call interface, context switch.
  • 2. Interrupts and Exceptions: • The system is responsible for handling interrupts, whether they result from hardware (such as from the clock or from peripheral devices), from a programmed interrupt (execution of instructions designed to cause “software interrupt”, or from exceptions (such as page faults). • If the CPU is executing at a lower processor execution level than the level of the interrupt it accepts the interrupt before decoding the next instruction and raises the processor execution level, so that no other interrupts of the level (or lower level) can happen while it handles the current interrupt, preserving the integrity of the kernel data structure.
  • 3. The kernel handles the interrupt with the following sequence of operations: 1. It saves the current register context of the executing process and creates (pushes) a new context layer. 2. It determines the “source” or cause of the interrupt, identifying the type of interrupt (such as clock or disk) and the unit number of the interrupt, if applicable (such as which disk drive caused the interrupt). 3.When the system receives an interrupt, it gets a number from the machine that it uses as an offset into a table known as interrupt vector. 4.The contents of interrupt vector vary from machine to machine, but they usually contain the address of the interrupt handler for the corresponding interrupt source, and a way of finding a parameter for the interrupt handler.
  • 4. For e.g. consider the interrupt handler table (fig 9)
  • 5. The kernel invokes the interrupt handler. • The kernel stack for the new context layer is logically distinct from the kernel stack of the previous context layer. • Some implementations use the kernel stack of the executing process to store the interrupt handler stack frames, and other implementations use a global interrupt stack to store the frames for the interrupt handlers that are guaranteed to return without switching context.
  • 6. The interrupt handler completes its work and returns. • The kernel executes a machine-specific sequence of instructions that restores the register context and kernel stack of the previous context layer, as they existed at the time of the interrupt and then resumes execution of the restored context layer. • The behavior of the process may be affected by the interrupt handler, since the interrupt handler may have altered the global kernel data structures and awakened sleeping process. • Usually the process continues execution as if the interrupt had never happened.
  • 7.
  • 8.
  • 9. System call Interface: • The System call is a normal function call. • The usual calling sequence cannot change the mode of a process from user to kernel. • The C compiler uses a predefined library of functions that have the names of the system calls, thus resolving the system call references in the user program. • The library functions typically invoke an instruction that changes the process execution mode to kernel mode and causes the kernel to start executing code for system calls.
  • 10.
  • 11. Context Switch: • The kernel permits a context switch under four circumstances: (fig 1) • 1) when a process puts itself to sleep, • 2) when it exits, • 3) when it returns from a system call to user mode but is not the most eligible process to run, or • 4) when it returns to user mode after the kernel completes handling an interrupt but is not the most eligible process to run.
  • 12. • The kernel ensures integrity and consistency of internal data structures by prohibiting arbitrary context switches. • It makes sure that the state of its data structures is consistent before it does a context switch: • i.e. that all appropriate updates are done, • that queues are properly linked, • that appropriate locks are set to prevent intrusion by other processes, that no data structures are left unnecessarily locked and so on. • For e.g. if the kernel allocates a buffer, reads a block in a file, and goes to sleep waiting for I/O transmission from the disk to complete, it keeps the buffer locked so that no other process can tamper with the buffer. • But if a process executes the link system call, the kernel releases the lock of the first inode before locking the second inode to avoid deadlock. • The kernel must do a context switch at the conclusion of the exit system call, because there is nothing else for it to do.
  • 13. The procedure for a context switch is similar to the procedures for handling interrupts and system calls, except that the kernel restores the content layer of a different process instead of the previous context layer of the same process. Similarly, the choice of which process to schedule next is a policy decision that does not affect the mechanics of the context switch.
  • 14.
  • 15. From fig 16; the function save_context( ) saves information about the context of the running process and returns the value1. 1.Among other pieces of information, the kernel saves the value of the current program counter (in the function save_context( )) and the value 0, to be used later as the return value in register 0 from save_context. 2.The kernel continues to execute in the context of the old process (A), picking another process (B) to run and calling resume_context( ) to restore the new context (of B). 3.After the new context is restored, the system is executing process B; the old process (A) is no longer executing but leaves its saved context behind. (hence the comment in the fig 16. “never gets here”). 4.Later, the kernel will again pick process A to run (except for exit case) when another process does a context switch, as just described. 5.When process A’s context is restored, the kernel will set the program counter to the value process A had previously saved in the function save_context, and it will also place the value 0, saved for the return value, into register 0. 6.The kernel resumes execution of process A inside save_context even though it had executed the code up to the call to resume_context before the context switch. 7.Finally, process A returns from the function save_context with the value 0 (in reg 0) and resumes execution after the comment line “resuming process executes from here”.
  • 16. Saving context for abortive returns • Situations arise when the kernel abort its current execution sequence and immediately execute out of a previously saved contest. • Sleep and signals describe the circumstances when a process must suddenly change its contest; • 1.Explains the mechanisms for executing a previous contest. • The algorithm to save a contest is setup and the algorithm to restore the contest is longjmp • 2.The method is identical to the function save context , except that save context pushes a new context larger where as setjmp stores the saved context in the u area and continues to execute in the old context larger. • 3.When the kernel wishes to resume the context it had saved in setjmp ,if does a long.restoring its context from the u area and returning a 1 from setjmp.
  • 17. Copying data between system and user address space • A process executes in kernel mode or in user mode with no overlap of modes. • Many system calls move data between kernel and user space, such as when copying system call parameters from user to kernel space or when copying data fron I/O buffers in the read system call. • Many machines allow the kernel to reference addresses in user space directly. • The kernel must ascertain, that the address being read or written is accessible as if it had been executing in user mode; • o Otherwise it could override the ordinary protection mechanisms and inadvertently read or write addresses outside the user address space (possibly kernel data structure).