Starting from:
$30

$24

Operating System Lab Assignment 13 Solution

Q1) Write a C program parmax.c that creates a tree of processes in order to recursively compute the maximum in an array of integers. The process at the root of the tree reads the count n of integers in the array as a command-line parameter. An array A of size n is then populated with randomly generated integers of small values (in the range 0–127). The initially unsorted array is printed by the root process.




Any process in the tree handles a chunk of the array A. The chunk is delimited by two indices L and R. For the root process, L = 0 and R = n – 1. Any process P in the tree (including the root) first counts the number of integers in the chunk it has got. If that count is less than 10, the process P itself computes the maximum element in its chunk, prints it, and exits. If the chunk size of P is 10 or more, then P creates two child processes PL and PR which handle the chunks [L, M] and [M + 1, R] in A respectively, where M = (L + R) / 2. P waits until the two child processes PL and PR exit. It then computes the maximum of the two maximum values computed by PL and PR, prints this maximum, and exits.




Every non-root process returns to its parent (via the exit status) the maximum value for its chunk. During the printing of the maximum computed by a process P, the PID and the parent PID of P are also printed.

For n = 50, the ranges of the chunks handled by different processes in the tree are shown below. [0 – 49]








/




\






[0 – 24]






[25 – 49]




/
\




/
\


[0 – 12]
[13 – 24]




[25 – 37]
[38 – 49]


/
\
/
\
/
\
/
\
[0 – 6]
[7 – 12]
[13 – 18]
[19 – 24]
[25 – 31] [32 – 37]
[38 – 43] [44 – 49]



We expect your code to handle values of n in the range 50 – 100.

More products