CS34 2013-05-17 CS 134: Operating Systems Processes CS 134: Operating Systems Processes 1 / 25
Overview CS34 Overview 2013-05-17 Processes Processes in Unix Implementation States Overview Threads Concepts Uses Models Design Processes Processes in Unix Implementation States Threads Concepts Uses Models Design 2 / 25
Processes Processes & Concurrency CS34 Processes & Concurrency 2013-05-17 Processes What is a process? Processes & Concurrency What is concurrency? What is a process? What is concurrency? 3 / 25
Processes User’s View of Processes CS34 User’s View of Processes 2013-05-17 Processes A fundamental OS abstraction ◮ But details vary from OS to OS: ◮ Batch system—Jobs ◮ Time-shared systems—User programs or tasks ◮ Common idea: Process = “A program in execution” User’s View of Processes ◮ Processes have a degree of independence from each other ◮ Possibly only allowed communicate through designated mechanisms ◮ One errant processes should not affect other unrelated ones A fundamental OS abstraction ◮ But details vary from OS to OS: ◮ Batch system—Jobs ◮ Time-shared systems—User programs or tasks ◮ Common idea: Process = “A program in execution” ◮ Processes have a degree of independence from each other ◮ Possibly only allowed communicate through designated mechanisms ◮ One errant processes should not affect other unrelated ones 4 / 25
Processes Class Exercise CS34 Class Exercise 2013-05-17 Processes What makes up a process? (“A process has. . . ”) ◮ In general Class Exercise ◮ On a typical POSIX system What makes up a process? (“A process has. . . ”) ◮ In general ◮ On a typical POSIX system 5 / 25
Processes Processes in Unix Components of a Process (Unix) CS34 Components of a Process (Unix) 2013-05-17 ◮ Execution state ◮ I/O State Processes ◮ Registers ◮ File descriptors ◮ Program counter ◮ Working directory ◮ Program status word ◮ Root directory ◮ Stack pointer Processes in Unix ◮ Event Notifications ◮ Signals waiting ◮ Scheduling information ◮ Process state ◮ Signal mask ◮ Priority ◮ Time of next alarm Components of a Process (Unix) ◮ Class, etc. ◮ Other ◮ Execution state ◮ I/O State ◮ Memory ◮ Process ID ◮ Text area ◮ Parent process ◮ Data area ◮ Process group ◮ Stack area ◮ Controlling terminal ◮ Registers ◮ File descriptors ◮ Security/Authentication Info ◮ Start time ◮ User ID ◮ CPU time ◮ Children’s CPU time ◮ Group ID ◮ Program counter ◮ Working directory ◮ Program status word ◮ Root directory ◮ Stack pointer ◮ Event Notifications ◮ Scheduling information ◮ Signals waiting ◮ Process state ◮ Signal mask ◮ Priority ◮ Time of next alarm ◮ Class, etc. ◮ Other ◮ Memory ◮ Process ID ◮ Text area ◮ Parent process ◮ Data area ◮ Process group ◮ Stack area ◮ Controlling terminal ◮ Start time ◮ Security/Authentication Info ◮ CPU time ◮ User ID ◮ Children’s CPU time ◮ Group ID 6 / 25
Processes Processes in Unix Processes under UNIX CS34 Processes under UNIX 2013-05-17 Processes Processes: Processes in Unix ◮ Create with fork ◮ Exit with exit ◮ Replace “process image” with execve Processes under UNIX Multiple processes may be active at any one time (compare w/ uniprogrammed system) Processes: ◮ Create with fork ◮ Exit with exit ◮ Replace “process image” with execve Multiple processes may be active at any one time (compare w/ uniprogrammed system) 7 / 25
Processes Processes in Unix Class Question CS34 Class Question 2013-05-17 Processes Processes in Unix If there’s fork , should we have join ? Class Question If there’s fork , should we have join ? 8 / 25
Processes Processes in Unix Processes under UNIX CS34 Processes under UNIX 2013-05-17 The environment you interact with is made up of processes Processes nobody mDNSResponder p2 ssh lookupd man p1 Processes in Unix distnoted configd -tcsh DirectoryService -tcsh coreservicesd SystemUIServer sh less AppleSpell mach_init KernelEventAgent diskarbitrationd automount login Safari Finder login sh ATSServer rpc.lockd crashreporterd p4 Processes under UNIX cron pbs System login SystemStarter syslogd melissa -tcsh The environment you interact with is made up of processes root xinetd loginwindow Preview Terminal update WindowServer login -tcsh SecurityServer init TabletDriverRelauncher cupsd Keynote TeXShop dynamic_pager Dock login ps nfsiod TabletDriver p3 automount ntpd kextd MouseWorks login TextEdit -tcsh notifyd p6 netinfod UniversalAccess -tcsh p5 nobody p2 mDNSResponder ssh lookupd man p1 distnoted configd -tcsh DirectoryService -tcsh coreservicesd SystemUIServer sh less AppleSpell KernelEventAgent mach_init diskarbitrationd automount login Safari sh login Finder rpc.lockd p4 ATSServer crashreporterd cron pbs System login melissa -tcsh syslogd SystemStarter root loginwindow Preview xinetd Terminal update WindowServer -tcsh login init SecurityServer TabletDriverRelauncher Keynote cupsd TeXShop dynamic_pager login ps Dock nfsiod TabletDriver p3 ntpd kextd MouseWorks automount login TextEdit -tcsh p6 notifyd netinfod UniversalAccess -tcsh p5 9 / 25
Processes Implementation Process Implementation CS34 Process Implementation 2013-05-17 Processes Implementation How does the OS implement the process abstraction? Process Implementation How does the OS implement the process abstraction? 10 / 25
Processes Implementation Process Implementation (cont’d) CS34 Process Implementation (cont’d) 2013-05-17 Processes The OS needs to maintain a process image for each process: Implementation ◮ Process’s address space, containing: ◮ Program code ◮ Program data ◮ Processor stack Process Implementation (cont’d) ◮ Housekeeping information ( PCB ) ◮ One of most important is process state The OS needs to maintain a process image for each process: ◮ Process’s address space, containing: ◮ Program code ◮ Program data ◮ Processor stack ◮ Housekeeping information ( PCB ) ◮ One of most important is process state 11 / 25
Processes States A Two-State Process Model CS34 A Two-State Process Model 2013-05-17 Processes Simplest model for processes: States Not A Two-State Process Model Running Running Simplest model for processes: Not Running Running 12 / 25
Processes States A Four-State Process Model CS34 A Four-State Process Model 2013-05-17 Processes More useful model for processes: States Ready Running Finished A Four-State Process Model Blocked More useful model for processes: Ready Running Finished Blocked 13 / 25
Processes States A Five-State Process Model CS34 A Five-State Process Model 2013-05-17 Processes Five states can model additional needs of batch systems: States New Ready Running Finished A Five-State Process Model Blocked Scheduler queues: Five states can model additional needs of batch systems: ◮ Ready queue: Processes ready and waiting to execute. ◮ New queue: Processes waiting to be created New Ready Running Finished Blocked Scheduler queues: ◮ Ready queue: Processes ready and waiting to execute. ◮ New queue: Processes waiting to be created 14 / 25
Threads Concepts Generalizing Processes CS34 Generalizing Processes 2013-05-17 Threads Concepts Simple view of process is Address space + Thread of execution Generalizing Processes Does the mapping need to be one-to-one? Simple view of process is Address space + Thread of execution Does the mapping need to be one-to-one? 15 / 25
Threads Concepts Possible Mappings CS34 Possible Mappings 2013-05-17 Threads Concepts one process� one process� one thread� multiple threads� � � Possible Mappings multiple processes� multiple processes� one thread per process� multiple threads per process� � � one process� one process� one thread� multiple threads� � � multiple processes� multiple processes� one thread per process� multiple threads per process� � � 16 / 25
Threads Concepts Threads CS34 Threads 2013-05-17 Threads Concepts Motivation: ◮ Traditional processes: Virtual uniprocessor machine ◮ Multithreaded processes: Virtual multiprocessor machine Threads Motivation: ◮ Traditional processes: Virtual uniprocessor machine ◮ Multithreaded processes: Virtual multiprocessor machine 17 / 25
Threads Uses Uses of Threads CS34 Uses of Threads 2013-05-17 Threads Various reasons why people use threads Uses ◮ Performing foreground and background work ◮ Supporting asynchronous processing Uses of Threads ◮ Speeding execution ◮ Organizing programs Various reasons why people use threads ◮ Performing foreground and background work ◮ Supporting asynchronous processing ◮ Speeding execution ◮ Organizing programs 18 / 25
Recommend
More recommend