资源描述
Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,3.,Silberschatz,Galvin and Gagne 2018,Operating System Concepts 10,th,Edition,Chapter 3:Processes,Chapter 3:Processes,Process Concept,Process Scheduling,Operations on Processes,Interprocess Communication,IPC in Shared-Memory Systems,IPC in Message-Passing Systems,Examples of IPC Systems,Communication in Client-Server Systems,Process Concept,An operating system executes a variety of programs that run as a process.,Process,a program in execution;process execution must progress in sequential fashion,Multiple parts,The program code,also called,text section,Current activity including,program,counter,processor registers,Stack,containing temporary data,Function parameters,return addresses,local variables,Data section,containing global variables,Heap,containing memory dynamically allocated during run time,Process in Memory,Memory Layout of a C Program,Process State,As a process executes,it changes,state,New,:The process is being created,Running,:Instructions are being executed,Waiting,:The process is waiting for some event to occur,Ready,:The process is waiting to be assigned to a processor,Terminated,:The process has finished execution,Diagram of Process State,Process Control Block(PCB),Information associated with each process,(also called,task control block,),Process state running,waiting,etc,Program counter location of instruction to next execute,CPU registers contents of all process-centric registers,CPU scheduling information-priorities,scheduling queue pointers,Memory-management information memory allocated to the process,Accounting information CPU used,clock time elapsed since start,time limits,I/O status information I/O devices allocated to process,list of open files,Threads,So far,process has a single thread of execution,Consider having multiple program counters per process,Multiple locations can execute at once,Multiple threads of control-,threads,Must then have storage for thread details,multiple program counters in PCB,Explore in detail in Chapter 4,Process Representation in Linux,Represented by the C structure,task_struct,pid_t pid;/*process identifier*/long state;/*state of the process*/unsigned int time_slice/*scheduling information*/struct task_struct*parent;/*this process,s parent*/struct list_head children;/*this process,s children*/struct files_struct*files;/*list of open files*/struct mm_struct*mm;/*address space of this process*/,Process Scheduling,Maximize CPU use,quickly switch processes onto CPU core,Process scheduler,selects among available processes for next execution on CPU core,Maintains,scheduling queues,of processes,Ready queue,set of all processes residing in main memory,ready and waiting to execute,Wait queues,set of processes waiting for an event(i.e.I/O),Processes migrate among the various queues,Ready and Wait Queues,Representation of Process Scheduling,CPU Switch From Process to Process,A,context switch,occurs when the CPU,switches from one process to another.,Context Switch,When CPU switches to another process,the system must,save the state,of the old process and load the,saved state,for the new process via a,context switch,Context,of a process represented in the PCB,Context-switch time is overhead;the system does no useful work while switching,The more complex the OS and the PCB,the,longer the context switch,Time dependent on hardware support,Some hardware provides multiple sets of registers per CPU,multiple contexts loaded at once,Process,Operation:,Creation,Parent,process create,children,processes,which,in turn create other processes,forming a,tree,of processes,Generally,process identified and managed via a,process identifier,(,pid,),Resource sharing options,Parent and children share all resources,Children share subset of parent,s resources,Parent and child share no resources,Execution options,Parent and children execute concurrently,Parent waits until children terminate,A Tree of Processes in Linux,Process Creation(Cont.),Address space,Child duplicate of parent,Child has a program loaded into it,UNIX examples,fork(),system call creates new process,exec(),system call used after a,fork(),to replace the process,memory space with a new program,Parent process calls,wait(),for the child to terminate,C Program Forking Separate Process,Process Termination,Process executes last statement and then asks the,OS,to delete it using the,exit(),system call.,Returns status data from child to parent(via,wait(),),Process,resources are deallocated by OS,Parent may terminate the execution of children processes using the,abort(),system call.Some reasons for doing so:,Child has exceeded allocated resources,Task assigned to child is no longer required,The parent is exiting and the OS does not allow a child to continue if its parent terminates,Process Termination,Some,OSs,do not allow child to exists if its parent has terminated.If a process terminates,then all its children must also b
展开阅读全文