New version page

UH COSC 6310 - Programming Assignment 1 - Pipes and Process Synchronization

Upgrade to remove ads
Upgrade to remove ads
Unformatted text preview:

COSC 3360/6310 - Operating Systems Fall 2020Programming Assignment 1 - Pipes and Process SynchronizationDue Date: Wednesday, October 5, 2020, 11:59pm CDTObjectivesThis assignment will help you understand several basic UNIX/Linux primitives, implemented atthe process management layer of an operating system, such as fork(), pipe(), and execv() as wellas simple process synchronization and dataflow systems.In this assignment, you will implement a program to synchronize, with Unix/Linux pipes,concurrent processes which perform arithmetic operations. You will learn concepts from severalcomputer science disciplines, including data flow architecture, parallel computation, computer arith-metic, an d, of course, operating systems. The input (passed as the first argument of your mainprogram) to your program is a process precedence/dataflow graph specified in the following format:input_var a,b,c,d;vertex v0 = PLUS, v1 = MINUS, v2 = DIVIDE, v3 = TIMES;a -> v0;b -> v1 -> v0;c -> v0;c -> v1;v1 -> v0;c -> v2;d -> v2 -> v3;a -> v3;v0 -> v3;write(a,b,c,d,v0,v1,v2,v3).input_vardeclares input variables to be read by your program. Each input value (after it is read) is storedin a process you create.vertexdeclares vertices representing arithmetic operators (PLUS, MINUS, TIMES, DIVIDE) in the prece-dence graph whose values will be computed by processes you create. There will be a distinct pr ocessto handle the calculation for each vertex variable.To keep the input simple, the values of the input variables to be read by your program willbe in the same ord er they appear in the inputvar declaration. There w ill be no syntax/semanticerrors. However, there may be duplicates, that is, an edge is specified more than once but only asingle pipe should be created for these duplicates. Also, ther e are at most 10 input variables and10 vertices.Example for reading input variables:In the above example,input_var a,b,c,d;the values of a,b,c,d are stored in an input file or stdin. For example, an input file may contain:1 2 3 4Your program should work for different sets of values for the input variables.Precedence/Dataflow GraphA variable name beginning with ‘v’ represents a vertex or vertex variable. Other variable namesrepresent input variables. In the example above,vertex v0 = PLUS, v1 = MINUS, v2 = DIVIDE, v3 = TIMES;v0 per forms the + operation, v1 performs the - operation, v2 performs the / operation, and v3performs the * operation. Note that the MINUS and DIVIDE operators are b inary (each takestwo operands or values) so each operation needs two input values; while the PLUS and TIMESoperators may each have two or more inpu ts. For the MINUS and DIVIDE operators, the inputwith the larger value is the first operand. If the input values are equal, then either value can bethe first operand. Note that for MINUS, the output is always 0; for DIVIDE, the output is always1. For example, if two numbers, 9 and 3, are inputs for the DIVIDE operator, then the arithmeticoperation is 9/3 = 3. Similary, for the MINUS operator, the arithmetic operation is 9 - 3 = 6.A pipe connects an input variable i (also stored in a process) or process vx to another processvy if process vy depends on i or vx, th at is, a value is sent from i or vx to vy. For examp le,a -> v0;means that the value of input variable a is sent via a pipe to v0. Note that for an arithmeticoperation in a vertex vx to start, all the inpu ts to this vertex must be available, that is, theseinputs are in the r espective pipes for reading by process vx.In the above example snippet:a -> v0;b -> v1 -> v0;c -> v0;c -> v1;v1 -> v0;means that the value in process a (with an input value) is passed to process v0 via a pipe; thevalue in process b (with another input value) is passed to process v1 via another pipe and thenthe value calculated in v1 (after performing the MINUS operation c - b = 3 - 2 = 1) is passed toprocess v0 via yet another pipe; and the value in process c (with yet another input value) is passedto processes v0 and v 1 via two other pipes. Note that the last line in this example snippet specifiesthe same edge (duplicate) fr om v1 to v0 in the second line, so no new pipe is created h er e betweenv1 and v0. Then process v0 performs the PLUS operation on the values from a, c, and v1 (1 + 3+ 1).Therefore, the above process precedence/dataflow graph corresponds to the following arithmeticformula:a * (a + c + (c - b)) * (d / c)2Note that no parentheses need to be specified by the precedence graph with the arithmeticoperations. Also, arithm etic operations are performed from left to right; hence you should readthe specifications of the precedence graph in the order they appear. T he specifications end with a‘write’ statement.The output of your program consists of a printout of the values of all input an d vertex variablesafter all the arithmetic operations have completed.Submitting the program:For s ubmission guidelines, please visit Blackboard /TAs’ instructions.NotesBefore you start your assignment, f amiliarize yourself with th e way C/C++ programs handle argu-ments that are passed to them by execv() and with the UNIX functions fork(), pipe() an d dup().The programs you turn in shou ld be well documented. Each C/C++ function should start bya brief description of its purpose and its parameters. Each variable declaration should contain abrief description of the variable(s) being declared.Code-level plagiarism is forbidden. If you copy code(s) from any source, including those fromstudents who previously took the course and any online source, please explicitly cite it. Even withexplicit citations, the logical similarity to any codes available online or submitted either this yearor previous years should be less than 75%. Otherwise, you may end up receiving a 0 for

View Full Document
Download Programming Assignment 1 - Pipes and Process Synchronization
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...

Join to view Programming Assignment 1 - Pipes and Process Synchronization and access 3M+ class-specific study document.

We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Programming Assignment 1 - Pipes and Process Synchronization 2 2 and access 3M+ class-specific study document.


By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?