Class Note for CMPSCI 377 at UMass(34)
Class Note for CMPSCI 377 at UMass(34)
Popular in Course
Popular in Department
This 3 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Massachusetts taught by a professor in Fall. Since its upload, it has received 16 views.
Reviews for Class Note for CMPSCI 377 at UMass(34)
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
CMPSCI 377 Operating Systems Fall 2008 Lecture 5 September 16 Lecturer Prashaut Sherwy Scribe Shashz39 Singh 51 Process Management 511 Process A process is an instance of a computer program that is being sequentially executed by a computer system that has the ability to run several computer programs concurrently A computer program itself is just a passive collection of instructions while a process is the actual execution of those instructions Several processes may be associated with the same program for example opening up several windows of the same program typically means more than one process is being executed The state of a process consists of code for the running program its static data heap and the heap pointer HP program counter stack and the stack pointer value of CPU registers set of OS resources in use list of open les etc process execution state new ready running etc 512 Process Execution State Processes go through various process states which determine how the process is handled by the operating system kernel The speci c implementations of these states vary in different operating systems and the names of these states are not standardised but the general highlevel functionality is the same When a process is rst startedcreated it is in new state It needs to wait for the process scheduler of the operating system to set its status to 77new77 and load it into main memory from secondary storage device such as a hard disk or a CD ROM Once it is loaded into memory it enters ready state Once the process has been assigned to a processor by a shortterm scheduler a context switch is performed loading the process into the processor and the process state is set to running where the processor executes its instructions If a process needs to wait for a resource such as waiting for user input or waiting for a le to become available it is moved into the em wating state until it no longer needs to wait then it is moved back into the em ready state Once the process nishes execution or is terminated by the operating system it is moved to the terminated state where it waits to be removed from main memory The OS manages multiple active process using state queues 513 Process Control Block A Process Control Block is a data structure in the operating system kernel containing the information needed to manage a particular process The PCB is 77the manifestation of a process in an operating system A PCB will include the identi er of the process a process identi er or PlD register values for the process including the program counter the address space for the process priority process accounting information such as when the process was last run how much CPU time it has accumulated etc pointer to the next PCB ie pointer to the PCB of the next process to run lO Information ie lO devices allocated to this process list of opened les etc Since the PCB contains the critical information for the process it must be 51 52 Lecture 5 September 16 kept in an area of memory protected from normal user access In some operating systems the PCB is placed in the beginning of the kernel stack of the process since that is a convenient protected location 514 Process State Queues The OS maintains the PCBs of all processes in state queues PCBs of all processes in the same execution state is placed in the same queue When the state of a process is changed7 its PCB is unlinked from its current queue and moved to its new state queue The OS can use different policies to manage each queue FIFO7 Round Robin7 Priority etc Each lO device has its own wait queue 515 Context Switch A context switch is the computing process of storing and restoring the state context of a CPU such that multiple processes can share a single CPU resource The context switch is an essential feature of a multitasking operating system Context switches are usually computationally intensive and much of the design of operating systems is to optimize the use of context switches There are three scenarios where a context switch needs to occur multitasking7 interrupt handling7 user and kernel mode switching In a context switch7 the state of the rst process must be saved somehow7 so that7 when the scheduler gets back to the execution of the rst process7 it can restore this state and continue The state of the process includes all the registers that the process may be using7 especially the program counter7 plus any other operating system speci c data that may be necessary Often7 all the data that is necessary for state is stored in one data structure7 called a process control block 516 Creating a Process fork System Call A process can create other processes to do work In computing7 when a process forks7 it creates a copy of itself7 which is called a 77child process The original process is then called the 77parent process More generally7 a fork in a multithreading environment means that a thread of execution is duplicated7 creating a child thread from the parent thread Under Unix and Unixlike operating systems7 the parent and the child processes can tell each other apart by examining the return value of the fork system call In the child process7 the return value of fork is 07 whereas the return value in the parent process is the PD of the newlycreated child process The fork operation creates a separate address space for the child The child process has an exact copy of all the memory segments of the parent process7 though if copyon write semantics are implemented actual physical memory may not be assigned ie7 both processes may share the same physical memory segments for a while Both the parent and child processes possess the same code segments7 but execute independently of each other The child process usually executes the exec function to do something useful The exec functions of Unixlike operating systems are a collection of functions that causes the running process to be completely replaced by the program passed as argument to the function As a new process is not created7 the process ID PlD does not change across and execute7 but the data7 heap and stack of the calling process are replaced by those of the new process In the eacecl7 eaceclp7 eacecv7 and execvp calls7 the child process inherits the parent s environment The parent process7 after creating the child process7 may issue a wait system call7 which suspends the execution of the parent process while the child executes When the child process terminates7 it returns an exit status to the operating system7 which is then returned to the waiting parent process The parent process then resumes execution Lecture 5 September 16 53 517 Process Termination On process termination7 OS reclaims all resources assigned to the process In Unix7 a process cana terminate itself using the exit system call A process can terminate another process if it has the privilege to do so using the kill system call 518 Cooperating Processes Cooperating processes work with each other to accomplish a single task This may improve performance by overlapping activities or performing work in parallel It helps tp easily share information between tasks It can enable an application to achieve a better program structure as a set of cooperating processes7 where each is smaller than a single monolithic program Distributed systems are examples of cooperating processes in action In computer science7 the producerconsumer problem also known as the boundedbuffer problem is a classical example of a multiprocess synchronization problem The problem describes two processes7 the producer and the consumer7 who share a common7 xedsize buffer The producers job is to generate a piece of data7 put it into the buffer and start again At the same time the consumer is consuming the data ie removing it from the buffer one piece at a time The problem is to make sure that the producer won7t try to add data into the buffer if it s full and that the consumer won t try to remove data from an empty buffer 519 Interprocess Communication InterProcess Communication lPC is a set of techniques for the exchange of data among two or more threads in one or more processes Processes may be running on one or more computers connected by a network lPC techniques are divided into methods for message passing7 synchronization7 shared memory7 and remote procedure calls RPC The method of lPC used may vary based on the bandwidth and latency of communication between the threads7 and the type of data being communicated 5 19 1 Message Passing message passing is a form of communication used in interprocess communication Communication is made by the sending of messages to recipients Each process should be able to name the other processes The consusmer is assumed to have an infnite buffer size The sender typically uses sendO system call to send messages7 and the receiver uses receiveO system call to receive messages These system calls can be either synchronous or asynchronous 5 19 2 Shared Memory Shared memory is a memory that may be simultaneously accessed by multiple programs with an intent to provide communication among them One process will create an area in RAM which other processes can access this is typically done using system calls mmap7 shmget etc Since both processes can access the shared memory area like regular working memory7 this is a very fast way of communication as opposed to other mechanisms of lPC On the other hand7 it is less powerful7 as for example the communicating processes must be running on the same machine whereas other lPC methods can use a computer network7 and care must be taken to avoid issues if processes sharing memory are running on separate CPUs and the underlying architecture is not cache coherent Since shared memory is inherently nonblocking7 it canlt be used to achieve synchronization
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'