DOC PREVIEW
UMass Amherst ECE 397A - Processes

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 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 8 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 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 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 job and process almost 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 Each process may be in one of the following states (names vary across various OS): 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 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 Process PCBs 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 Scheduling SchedulersDifferent 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 Scheduling Schedulers (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fork system call creates new processexec system call used after a fork to replace the process’ memory space with a new program.Processes Tree on a UNIX SystemAn example with fork() #include <unistd.h>#include <sys/wait.h>#include <stdio.h>main() {int parentID = getpid(); /* ID of this process */char prgname[1024];gets(prgname); /* read the name of program we start */int cid = fork();if (cid == 0) { /* I am the child process */execlp(prgname, prgname, 0);/* if the program prgname can be started then we never get to this line, because the child program is replaced by prgname */} else {/* I am the parent process */sleep(1); /* Give my child time to start */waitpid(cid, 0,0); /* wait for my child to terminate */}} After the fork() callProcess 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ConvenienceWays of cooperating Interprocess commnication (IPC) Shared memory A range in the memory space is shared between processes Message passing  Direct communication Indirect, e.g., through a mailbox Important to note that these ways are typically “logical” One can have a message passing implementation on top of shared memory hardware/abstraction One can have shared memory on top of message passing hardware/abstraction Producer-Consumer Problem Paradigm for cooperating processes, producer process produces information that is consumed by a


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?