View the step-by-step solution to:

Question

This question was created from quiz02.pdf https://www.coursehero.com/file/41994368/quiz02pdf/ how to solve this quiz? 3. (50 POINTS) The code below should have a single parent process read in a two dimensional
matrix, formatted similarly to inputs for Homework 1. The parent should then spawn exactly
one child for each column of the matrix. The children should only determine the maximum
value for one single column and then execute / bin/ e cho with an argument of that maximum
value. A child’s column should be assigned in the order it was spawned by the parent, and
the assignment should be bijective (one—to—one). The function listings from the man page for each library call are given below. Assume we have
all necessary includes. Find all the bugs. Hint: 10 points per bug found up to 50 total points. pid_t getpid£void); void *malloc(size_t size); int scanf(const char *format, ...); pid_t fork(void); pid_t wait(int *status); int execl(const char *path, const char *arg, ..., (char *) NULL); int main()
{
int max, stat, i, j;
int rows = 8;
int cola 4;
int pid = getpid();
int** matrix = (int**)malloc(rows*sizeof(int));
for (i = 0; i &lt; rows; ++i)
matrix[i] = (int*)malloc(rows*sizeof(int)); for (i = 0; i &lt; rows; ++i)
for (j = 0; j &lt; cols; ++j&gt;
scanfCWd&quot;, matrix  [j] ); for (i = 0; i &lt; cols; ++i)
if (!£ork())
for (j = 0; j &lt; rows; ++j)
if (matrix[i] [j] &gt; max)
max = matrix  [j]; if {getpid(} == pid)
for (i = 0; i &lt; cols; ++i)
wait(&amp;stat);
else
execl(&quot;/bin/echo&quot;, “echo&quot;, max, NULL); return EXIT_SUCCESS ;

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
• -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents