Starting from:

$30

CSE344-Homework 2 Solved

Objective
The objective is to have a process read an input file, interpret its contents as coordinates, and forward them for calculations to children processes. Then it will collect their outputs and make a final calculation.

Process P
Process P will read an ASCII file (denoted by inputfilepath) provided as a commandline argument. It will interpret every character in it as un unsigned byte. Consecutively read 3 bytes are interpreted as integer coordinates in a 3-dimensional space. Every i-th group of consecutive 10 coordinates it reads, are forwarded to a child process R_i. The child process R_i will be created by P using the fork+exec paradigm. The 10 coordinates will be passed to the child process as environment variables. Once P reaches the end of the file (or there are less than 10 coordinates left), P will collect the outputs of the calculations of its children processes. The outputs will take place in an output file (denoted by outputfilepath) and will be in the form of one matrix from each R_i. Then P will calculate the two matrices that are closest to each other with respect to the Frobenius norm, and print them on stdout and terminate.

•        The process P must not start collecting the outputs before all the children processes have finished their calculations.

•        The children processes must not access the output file simultaneously for writing.

./processP -i inputFilePath -o outputFilePath

Process R_i
Each process R_i will receive 10 3d integer coordinates as environment variables. The names of the variables are up to you. It will then calculate their covariance matrix and write it to the output file provided to P (the format is up to you). This means you need to pass the outputfilepath information to the child process from P, I recommend passing it as a commandline argument while creating R_i. Then R_i will terminate.

• If P receives SIGINT, it will forward the signal to all of its children, free all of its resources, close open files, and remove the output file, clean-up after its children and terminate. When the children receive the forwarded signal, they will terminate after freeing their resources as well. Be careful with the signal handler, remember what I told you during the lectures. Use the polling based paradigm I showed you for graceful exiting.

Output
Process P reading hw2/inputFile.dat

Created R_1 with (66,77,81),(110,91,34),...,(63,90,91) ...

Created R_34 with (61,17,11),(210,51,54),...,(33,60,75)

Reached EOF, collecting outputs from hw2/outputFile.dat

The closest 2 matrices are ... and ..., and their distance is 0.5.

More products