Unformatted text preview:

COMP 530 Operating Systems Processes Don Porter Portions courtesy Emmett Witchel 1 Intuitively one of these COMP 530 Operating Systems What is a process App App Daemon Libraries Libraries Libraries System Call Table 350 1200 Kernel Hardware User Super visor 2 2 AppHardwareLibrariesKernelAppLibrariesDaemonLibrariesSystem Call Table 350 1200 Intuitively one of these COMP 530 Operating Systems What is a process A process is a program during execution Program static file image Process executing program program execution state A process is the basic unit of execution in an operating system Each process has a number its process identifier pid Different processes may run different instances of the same program E g my javac and your javac process both run the Java compiler At a minimum process execution requires following resources Memory to contain the program code and data A set of CPU registers to support execution 3 COMP 530 Operating Systems Program to process We write a program in e g Java A compiler turns that program into an instruction list The CPU interprets the instruction list which is more a graph of basic blocks void X int b if b 1 int main int a 2 X a COMP 530 Operating Systems Process in memory What you wrote void X int b if b 1 int main int a 2 X a Data What is in memory main a 2 X b 2 Stack Heap void X int b if b 1 int main int a 2 X a Code Data COMP 530 Operating Systems Processes in your computer Windows Look at task manager via Ctrl Alt Del Mac Linux ps eaf 6 COMP 530 Operating Systems Putting the pieces together Programmer you Writes code using symbolic names x foo bar CPU Expects instructions that use memory addresses Recall from COMP 311 or other assembly course What are the operands for load store branch jump etc Addresses MIPS example ld 0x1000 r1 Compiler Converts symbolic names to memory locations And stores memory blueprints in binary file executable OS loader Arranges memory to match blueprints when creating a process 7 COMP 530 Operating Systems Where do processes come from When I type a out the binary runs right Really only true for static binaries more on this later In reality a loader sets up the program Usually a user level program Can also be in kernel or split between both 8 COMP 530 Operating Systems Where do processes come from In order to run a program the loader reads and interprets the executable file sets up the process s memory to contain the code data from executable pushes argc argv on the stack sets the CPU registers properly calls start Program starts running at start start args initialize java ret main args exit ret process is now running no longer think of program When main returns OS calls exit which destroys the process and returns all resources What bookkeeping does the OS need for processes 9 COMP 530 Operating Systems Keeping track of a process A process has code OS must track program counter code location A process has a stack OS must track stack pointer OS stores state of processes computation in a process control block PCB E g each process has an identifier process identifier or PID Data program instructions stack heap resides in memory metadata is in PCB which is a kernel data structure in memory COMP 530 Operating Systems Context Switching The OS periodically switches execution from one process to another Called a context switch because the OS saves one execution context and loads another COMP 530 Operating Systems What causes context switches Waiting for I O disk network etc Might as well use the CPU for something useful Called a blocked state Timer interrupt preemptive multitasking Even if a process is busy we need to be fair to other programs Voluntary yielding cooperative multitasking A few others Synchronization IPC etc COMP 530 Operating Systems Credit where credit is due Brilliant and ubiquitous instruction set architecture design for context switching All execution context effectively captured in CPU registers Context switch largely amounts Barfing register contents for one process to memory Slurping register contents for another from memory into registers 13 COMP 530 Operating Systems Keeping track of a process redux OS stores state of processes computation in a process control block PCB E g each process has an identifier process identifier or PID Data program instructions stack heap resides in memory metadata is in PCB which is a kernel data structure in memory PCB stores this register state COMP 530 Operating Systems Process life cycle Processes are always either Executing Waiting to execute or Blocked waiting for an event to occur Start Start Done Done Ready Ready Running Running Blocked Blocked 15 COMP 530 Operating Systems Process 2 I O Device Process contexts Process 1 main OS k read read save save state state main startIO schedule endio schedule interrupt save save state state restore restore state state User Process n User Process n User Program 2 User Process 2 User Program 2 User Process 2 User Process 1 User Process 1 System Software System Software Operating System Operating System Memory k 1 COMP 530 Operating Systems When a process is waiting for I O what is its state 1 Ready 2 Running 3 Blocked 4 Zombie 5 Exited COMP 530 Operating Systems CPU Scheduling Problem of choosing which process to run next And for how long until the next process runs Why bother Improve performance amortize context switching costs Improve user experience e g low latency keystrokes Priorities favor important work over background work Fairness We will cover techniques later 18 COMP 530 Operating Systems When does scheduling happen When a process blocks When a device interrupts the CPU to indicate an event occurred possibly un blocking a process When a process yields the CPU Preemptive scheduling Setting a timer to interrupt the CPU after some time Places an upper bound on how long a CPU bound process can run without giving another process a turn Non preemptive scheduling Processes must explicitly yield the CPU 19 COMP 530 Operating Systems Scheduling processes OS uses PCBs to represent a process Every resource is represented with a queue OS puts PCB on an appropriate queue Ready to run queue Blocked for IO queue Queue per device Zombie queue When CPU becomes available choose from ready to run queue When an event occurs remove waiting process from blocked queue move to ready queue Why use multiple processes in one app COMP 530 Operating Systems Consider a Web server get network message URL from client fetch URL data from disk


View Full Document

UNC-Chapel Hill COMP 530 - Processes

Download Processes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Processes 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 Processes 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?