Unformatted text preview:

Introduction 1 What is an Operating System The software that runs in protected kernel supervisor mode The software that provides an abstraction to the hardware for application programs The software that manages the hardware resources for application programs The software that controls system resources and the processes using these resources 5 6 2002 Moran OS Lecture 13 1 Systems get built in layers one view of the layers is Applications System call interface Kernel Device Drivers Operating System Hardware Machine Language Microprogramming Physical Devices The lowest layers provide services that are used by the higher layers Another view of the layers 1 Scripts 2 Applications and Utilities 3 System software 4 System Libraries 5 System call interface 6 Operating System kernel 7 Hardware 5 6 2002 Higher Levels of Abstraction Moran OS Lecture 13 2 OS Concepts We will talk about Processes Threads Mutual Exclusion Process Scheduling Deadlocks Memory Management Disk Scheduling this is less of an issue than it once was because the hardware has gotten much smarter but it points up very important concepts File systems I O Security 5 6 2002 Moran OS Lecture 13 3 System Calls 1 A system call is how a non operating system process communicates with and asks for services from the operating system Recall that the operating system runs in a privileged or protected mode so the system call crosses the protection boundary How a system call works put the parameters in a specific place including the number of the system call issue a trap to the OS OS examines the parameters to decide which system call is being invoked OS performs the work OS puts the return code in a specific place and returns from the trap 5 6 2002 Moran OS Lecture 13 4 System Calls 2 The scheduler may not schedule the process that invoked the system call next System calls can block for example a disk read may complete some time later other processes would be run while the original process was blocked Examples of system calls include read write open fork etc System calls are typically quite expensive compared to ordinary function calls 5 6 2002 Moran OS Lecture 13 5 Processes A program in execution a program and its state Process Creation When How Process Termination When How Process Hierarchies Control Inheritance Process States Running Blocked Ready Transition Diagram 5 6 2002 Moran OS Lecture 13 6 Processes 1 A process is a program in execution The process includes all of the state necessary for the OS to execute stop and restart the program This includes text data registers interrupt state signals etc Generally every process will have the illusion that it is running alone to completion Multiprogramming OS give the illusion that the programs execute alone In fact the OS is switching back and forth between processes this can also be called pseudo parallelism 5 6 2002 Moran OS Lecture 13 7 Processes 2 What the processes see the illusion that they run to completion A B compute C i o op compute sleep i o op sys call compute D i o op i o op wake i o op compute compute sys call compute i o op 5 6 2002 i o op i o op i o op i o op Moran OS Lecture 13 8 Processes 3 A system call B time expired C i o operation D sleep Processes are sequential and the operating system is running them all in turn C i o operation B i o operation A i o operation B etc Time 5 6 2002 Moran OS Lecture 13 9 Processes 4 Processes can be organized into hierarchies in Unix every process has a parent and every process is a descendant of init Processes can be thought of as having states executing in user mode executing in kernel mode not executing but ready to execute sleeping while it waits for some resource blocked Running user sys call or interrupt Unix Process State Diagram interrupt interrupt return Running kernel sleep Asleep wakeup 5 6 2002 Moran OS Lecture 13 return schedule process Ready to run 10 Processes 5 Tannenbaum s process state diagram is slightly different Running 1 2 1 block on i o 2 get interrupted by timeout 3 get rescheduled 4 i o becomes available 3 Ready Blocked 4 Note there is this new blocked state We get there by trying to perform i o that isn t ready This is captured in the previous diagram by the OS putting the process to sleep The scheduler causes transitions 2 3 Fair scheduling becomes important here A process can be interrupted by the scheduler or it can interrupt itself 5 6 2002 Moran OS Lecture 13 11 Processes 6 Implementation Process Table has an entry per process data structure that allows the OS to control a process Some things found in a process table entry PTE registers stack pointer CPU time used process id parent process id pointer to data segment pointer to text segment pointer to stack segment current directory open files signal masks etc We find all of these things in the task structure in Linux Look at linux sched h task lives here asm processor h thread struct lives here 5 6 2002 Moran OS Lecture 13 12 Interrupts Interrupt Vector contains the location of the interrupt handler for each device When an interrupt occurs the hardware saves the current processes state and then jumps to the location contained in the interrupt vector save the registers and create a new stack some OS run on the process stack this makes the default case easier but error handling gets much harder interrupt routine handles the interrupt potentially we may now have multiple runnable processes so we return to the scheduler scheduler decides which process to run 5 6 2002 Moran OS Lecture 13 13 Threads 1 Processes have a thread of execution Traditionally one thread of execution per process Threads multiple threads of execution in a process 5 6 2002 Per Process Per Thread address space global variables open files child processes signals permissions program counter registers stack state Moran OS Lecture 13 14 Threads 2 Threads have the same basic states as processes running ready blocked 5 6 2002 Moran OS Lecture 13 15 Threads 3 Why use threads threads are cheaper to create than processes compute servers lower variance threads share address space Implementation User threads vs Kernel threads User Threads processes each have a thread table processes create stacks for each thread processes save registers Kernel Threads kernel has a thread table 5 6 2002 Moran OS Lecture 13 16 Thread Issues Blocking user threads one blocks all block Scheduling kernel can be cleverer about scheduling user more flexible Scaling Issues with many many threads user threads scale


View Full Document

NYU CSCI-GA 2250 - Lecture Notes

Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?