DOC PREVIEW
UMass Amherst ECE 397A - Processes

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

The Big Picture So FarRPC calls, sharing files,…Security, distrib. file system, communicationDistributed systemsFilesManagement, PersistenceFile systemMouse, keyboard, IO related system callsInterrupt handling, concurrency with CPUIO devicesAddress spaceMemory Protection, management, VMMemory ProcessProcess management, protection, synchronizationProcessorUser level AbstractionsExample OS ServicesHW AbstractionChapter 4: Processes■Process Concept■Process Scheduling■Operations on Processes■Cooperating Processes■Interprocess Communication■Communication in Client-Server SystemsProcess Concept■An operating system executes a variety of programs:✦Batch system – jobs✦Time-shared systems – user programs or tasks■Textbook uses the terms joband processalmost interchangeably.■Process – a program in execution; process execution must progress in sequential fashion.■A process includes:✦program counter ✦stack✦data sectionProcess 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 process.✦terminated: The process has finished execution.Diagram of Process StateProcess Control Block (PCB)Information associated with each process in the OS, i.e., the process related data structure.The PCB contains:■Process state (running, waiting, …)■Program counter (value of PC)■Stack pointer, General purpose CPU registers ■CPU scheduling information (e.g., priority)■Memory-management information■Username of owner■I/O status information■Pointer to state queues, ..Process Control Block (PCB)Example Process State in MemoryWhat you wrote:void X(int b){If (b==1) ..}main(){int a = 2;X(a);}In memory:PC->CPU Switch From Process to ProcessPCBs and Hardware State■The OS starts executing a process by loading hardware registers from its PCB■While the process is running the CPU modifies the hw registers (PC, SP, ..)■When the process stops a process it saves the current values into the PCB■Going from one process to another is the context switch✦100 to 1000 switches per second✦Cost of CSW is related to the time periodProcess Scheduling QueuesQueues related to process scheduling:■Job queue – set of all processes in the system.■Ready 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 managed by the OS.Ready Queue And Various I/O Device QueuesRepresentation of Process SchedulingSchedulersDifferent schedulers in the OS:■Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.■Short-term scheduler (or CPU scheduler) –selects which process should be executed next and allocates CPU.Addition of Medium Term SchedulingSchedulers (Cont.)■Short-term scheduler is invoked very frequently (milliseconds) ⇒(must be fast).■Long-term scheduler is invoked very infrequently (seconds, minutes) ⇒(may be slow).■The long-term scheduler controls the degree of multiprogramming.■Processes can be described as either:✦I/O-bound process – spends more time doing I/O than computations, many short CPU bursts.✦CPU-bound process – spends more time doing computations; few very long CPU bursts.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.■Context-switch time is overhead; the system does no useful work while switching.■Time dependent on hardware support.Process Creation■Parent process create children processes, which, in turn create other processes, forming a tree of processes.■Resource sharing✦Parent and children share all resources.✦Children share subset of parent’s resources.✦Parent and child share no resources.■Execution✦Parent and children execute concurrently.✦Parent waits until children terminate.Process Creation (Cont.)■Address space✦Child duplicate of parent.✦Child has a program loaded into it.■UNIX examples✦forksystem call creates new process✦execsystem call used after a forkto replace the process’ memory space with a new program.Processes Tree on a UNIX SystemProcess Termination■Process executes last statement and asks the operating system to decide it (exit).✦Output data from child to parent (via wait).✦Process’ resources are deallocated by operating system.■Parent may terminate execution of children processes (abort).✦Child has exceeded allocated resources.✦Task assigned to child is no longer required.✦Parent is exiting.✔Operating system does not allow child to continue if its parent terminates.✔Cascading termination.Cooperating Processes■Independent process cannot affect or be affected by the execution of another process.■Cooperating process can affect or be affected by the execution of another process■Advantages of process cooperation✦Information sharing ✦Computation speed-up✦Modularity✦ConvenienceProducer-Consumer Problem■Paradigm for cooperating processes, producer process produces information that is consumed by a consumerprocess.✦unbounded-buffer places no practical limit on the size of the buffer.✦bounded-buffer assumes that there is a fixed buffer size.Bounded-Buffer – Shared-Memory Solution■Shared data#define BUFFER_SIZE 10Typedef struct {. . .} item;item buffer[BUFFER_SIZE];int in = 0;int out = 0;■Solution is correct, but can only use BUFFER_SIZE-1 elementsBounded-Buffer – Producer Process item nextProduced;while (1) {while (((in + 1) % BUFFER_SIZE) == out); /* do nothing */buffer[in] = nextProduced;in = (in + 1) % BUFFER_SIZE;}Bounded-Buffer – Consumer Processitem nextConsumed;while (1) {while (in == out); /* do nothing */nextConsumed = buffer[out];out = (out + 1) % BUFFER_SIZE;}Interprocess Communication (IPC)■Mechanism for processes to communicate and to synchronize their actions.■Message system – processes communicate with each other without resorting to shared variables.■IPC facility provides two operations:✦send(message) – message size fixed or variable ✦receive(message)■If Pand Qwish to communicate, they need to:✦establish a communication linkbetween them✦exchange messages via send/receive■Implementation of communication link✦physical (e.g.,


View Full Document

UMass Amherst ECE 397A - 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 2 2 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?