Presentation is loading. Please wait.

Presentation is loading. Please wait.

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.

Similar presentations

Presentation on theme: "More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments."— Presentation transcript:

1 More on Processes Chapter 3

2 Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments _a process control structure _ identification: process, parent process, user _ context of the execution: PC, SP, other registers _ control: scheduling (state, priority), resources (memory, opened files), IPC

3 Execution mode _most processors support at least two modes of execution: privileged(kernel-mode) and non-privileged (user-mode) for protection reasons _the portion of the OS executed in kernel-mode is called kernel (basic functions which must be protected from interference by user programs) _in kernel-mode the OS can do anything (no protection) _user processes execute in user-mode _in user-mode a process can access only its address space

4 Interrupts and traps _Interrupts: asynchronous _ external events (not related to the processor state) which occur independently of the instruction execution in the processor _ can be masked (specifically or not) _ Traps: synchronous _ conditionally or unconditionally caused by the execution of the current instruction _ Interrupts and traps force the processor to save the current state of execution and jump to a new state indicated in the interrupt vector

5 Mode switching _one or several bits in the processor status word (PS) indicate the current (sometimes also the previous) mode of execution _these bits can be changed explicitly while in kernel-mode but not in user-mode _the processor status word can be loaded from the interrupt vector along with the address of the interrupt handler _by setting the kernel mode bit in the interrupt vectors user processes enter kernel-mode to execute interrupt handlers

6 Signals _UNIX mechanism to upcall a handler indicated by the user process when an event occurs: segmentation violation, message arrival etc... _the kernel handles the event first, then puts an activation record on the user-level stack corresponding to the event handler _when the user process is scheduled next it executes the handler first _from the handler the user process returns to where it was when the event occurred

7 System calls _to request an OS service a process issues a system call _in monolithic OS a system call is implemented as a trap _when executing the user program code a process runs in user-mode _when executing the OS code corresponding to a system call a process runs in kernel-mode _in microkernel OS a system call is implemented as an IPC

8 System call in monolithic OS kernel mode user mode read(....) pc ps code for read system call trap interrupt vector for trap instruction iret in-kernel file system(monolithic OS)

9 Process creation _can be performed by the OS transparently to the user or can be made visible to the user as a system call _in UNIX a process (parent process) can spawn another process (child process) by calling fork _the child process is created as a copy of the parent process (process image and process control structure) except for the identification and scheduling state _parent and child processes run on two different address spaces => by default no memory sharing

10 Copy on Write (COW) _copy the entire process image is time consuming, optimizations are possible _code segment can be made read-only and shared _copy-on-write for data segments _ at fork time the data segment is mapped read-only and shared between the child and the parent process _ the copy is performed lazily, in page increments at first write

11 When to Switch a Process Clock interrupt –process has executed for the maximum allowable time slice I/O interrupt Memory fault –memory address is in virtual memory so it must be brought into main memory

12 When to Switch a Process Trap –error occurred –may cause process to be moved to Exit state Supervisor call –such as file open

13 Change of Process State Save context of processor including program counter and other registers Update the process control block of the process that is currently running Move process control block to appropriate queue - ready, blocked Select another process for execution

14 Change of Process State Update the process control block of the process selected Update memory-management data structures Restore context of the selected process

15 Execution of the Operating System Non-process Kernel –execute kernel outside of any process –operating system code is executed as a separate entity that operates in privileged mode Execution Within User Processes –operating system software within context of a user process –process executes in privileged mode when executing operating system code


17 Execution of the Operating System Process-Based Operating System –major kernel functions are separate processes –Useful in multi-processor or multi- computer environment

18 UNIX SVR4 Process Management Most of the operating system executes within the environment of a user process

19 Process switching _processor can switch modes from user to kernel and back to user while running the same process _process switching is the act of taking a process off the processor and replacing it with another one that is waiting to run _process switching occurs in kernel-mode and is a result of process scheduling that is performed when one of the following occurs: _ Time slice allocated to the process expires _ a blocking system call _ memory fault due to a page miss

20 Process switching in UNIX _each process has a kernel stack which is accessible only to the kernel but is part of the process image _each process has a page table which maps both its memory image and the kernel memory image _when switching mode from user to kernel, process switches to its kernel stack but doesn’t change the page table

21 Process switching in UNIX ( cont’d ) _ the execution state of the old process is saved on its kernel stack _ the kernel switches from the old address space to the address space of the process scheduled to run next _ the execution state of the new process to run is restored from its kernel stack

22 Inter-process communication _ most OSs provide several abstractions for inter- process communication: message passing, shared memory, etc.. _ communication requires synchronization between processes (i.e. data must be produced before it is consumed) _ synchronization can be implicit (message passing) or must be explicit (shared memory) _ explicit synchronization can be provided by the OS (semaphores, monitors, etc..) or can be achieved exclusively in user-mode (if processes share memory)

23 Message passing _ protected communication between different address spaces send (destination, message) receive(source, message) _ synchronization on send: _ asynchronous (non-blocking send) _ blocking send until the message “is sent” _ blocking send until the message is received _ synchronization on receive: _ asynchronous (non-blocking receive) _ blocking receive until message arrives

24 Message passing (cont’d) _ message addressing _ direct: specify the process _ indirect: specify the queue _ mutual exclusion using messages _ non-blocking send _ blocking receive

25 Message passing implementation _ two copy operations in a conventional implementation x=1 send(process2, &X) receive(process1,&Y) print Y process 1 process 2 X Y kernel buffers 1st copy 2nd copy kernel

26 Shared memory implementation _ no copying but synchronization is necessary X=1 print Y process 1 process 2 X Y kernel physical memory shared region

Download ppt "More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments."

Similar presentations

Ads by Google