ICS 143 - Principles of Operating SystemsOutlineProcess ConceptProcess StateProcess StatesProcess Control BlockProcess Scheduling QueuesProcess QueuesSlide 9SchedulersMedium Term (Time-sharing) SchedulerProcess ProfilesContext SwitchProcess CreationUNIX Process HierarchySlide 16UNIX Process CreationProcess TerminationCooperating ProcessesThreadsSlide 21Threads(Cont.)Threads (cont.)Slide 24Thread Support in Solaris 2Threads in Solaris 2Slide 27Interprocess Communication (IPC)Producer-Consumer using IPCCooperating Processes via Message PassingImplementation QuestionsDirect CommunicationIndirect CommunicationIndirect Communication using mailboxesMailboxes (cont.)Message BufferingMessage Problems - Exception ConditionsSlide 38Producer-Consumer ProblemSlide 40Bounded-buffer - Shared Memory SolutionBounded Buffer - Shared Memory SolutionSlide 43ICS 143 - Principles of Operating SystemsLectures 3 and 4 - Processes and ThreadsProf. Nalini [email protected]Process ConceptProcess SchedulingOperations on ProcessesCooperating ProcessesThreadsInterprocess CommunicationProcess ConceptAn operating system executes a variety of programsbatch systems - jobstime-shared systems - user programs or tasksjob and program used interchangeablyProcess - a program in executionprocess execution proceeds in a sequential fashionA process containsprogram counter, stack and data sectionProcess StateA process changes state as it executes.newnewadmittedinterruptI/O oreventcompletionSchedulerdispatchI/O orevent waitexitreadyrunningterminatedwaitingProcess StatesNew - The process is being created.Running - Instructions are being executed.Waiting - Waiting for some event to occur.Ready - Waiting to be assigned to a processor.Terminated - Process has finished execution.Process Control BlockContains information associated with each process•Process State - e.g. new, ready, running etc.•Program Counter - address of next instruction to be executed•CPU registers - general purpose registers, stack pointer etc. •CPU scheduling information - process priority, pointer•Memory Management information - base/limit information•Accounting information - time limits, process number•I/O Status information - list of I/O devices allocatedProcess Scheduling QueuesJob Queue - set of all processes in the systemReady Queue - set of all processes residing in main memory, ready and waiting to execute.Device Queues - set of processes waiting for an I/O device.Process migration between the various queues.Queue Structures - typically linked list, circular list etc.Process QueuesDeviceQueueReadyQueueProcess Scheduling QueuesSchedulersLong-term scheduler (or job scheduler) - •selects which processes should be brought into the ready queue. •invoked very infrequently (seconds, minutes); may be slow.•controls the degree of multiprogrammingShort term scheduler (or CPU scheduler) -•selects which process should execute next and allocates CPU.•invoked very frequently (milliseconds) - must be very fastMedium Term Scheduler•swaps out process temporarily•balances load for better throughputMedium Term (Time-sharing) SchedulerProcess ProfilesI/O bound process - •spends more time in I/O, short CPU bursts, CPU underutilized.CPU bound process - •spends more time doing computations; few very long CPU bursts, I/O underutilized.The right job mix:•Long term scheduler - admits jobs to keep load balanced between I/O and CPU bound processesContext SwitchTask that switches CPU from one process to another process•the CPU must save the PCB state of the old process and load the saved PCB state of the new process.Context-switch time is overhead; •system does no useful work while switching•can become a bottleneckTime for context switch is dependent on hardware support ( 1- 1000 microseconds).Process CreationProcesses are created and deleted dynamicallyProcess which creates another process is called a parent process; the created process is called a child process.Result is a tree of processes e.g. UNIX - processes have dependencies and form a hierarchy.Resources required when creating processCPU time, files, memory, I/O devices etc.UNIX Process HierarchyProcess CreationResource sharing•Parent and children share all resources.•Children share subset of parent’s resources - prevents many processes from overloading the system.•Parent and children share no resources.Execution•Parent and child execute concurrently.•Parent waits until child has terminated.Address Space•Child process is duplicate of parent process.•Child process has a program loaded into it.UNIX Process CreationFork system call creates new processesexecve system call is used after a fork to replace the processes memory space with a new program.Process TerminationProcess executes last statement and asks the operating system to delete it (exit).•Output data from child to parent (via wait).•Process’ resources are deallocated by operating system.Parent may terminate execution of child processes.•Child has exceeded allocated resources.•Task assigned to child is no longer required.•Parent is exiting–OS does not allow child to continue if parent terminates–Cascading terminationCooperating ProcessesConcurrent Processes can be •Independent processes –cannot affect or be affected by the execution of another process.•Cooperating processes –can affect or be affected by the execution of another process.Advantages of process cooperation:–Information sharing–Computation speedup–Modularity–Convenience(e.g. editing, printing, compiling)Concurrent execution requires–process communication and process synchronizationThreadsProcesses do not share resources well •high context switching overheadA thread (or lightweight process) •basic unit of CPU utilization; it consists of:–program counter, register set and stack spaceA thread shares the following with peer threads:–code section, data section and OS resources (open files, signals)Collectively called a task.Heavyweight process is a task with one thread.ThreadsProgram counterThreads(Cont.)In a multiple threaded task, while one server thread is blocked and waiting, a second thread in the same task can run.Cooperation of multiple threads in the same job confers higher throughput and improved
View Full Document