View the step-by-step solution to:


This question was created from quiz02.pdf


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 < rows; ++i)
matrix[i] = (int*)malloc(rows*sizeof(int)); for (i = 0; i < rows; ++i)
for (j = 0; j < cols; ++j>
scanfCWd", matrix [1] [j] ); for (i = 0; i < cols; ++i)
if (!£ork())
for (j = 0; j < rows; ++j)
if (matrix[i] [j] > max)
max = matrix [1] [j]; if {getpid(} == pid)
for (i = 0; i < cols; ++i)
execl("/bin/echo", “echo", max, NULL); return EXIT_SUCCESS ;

Recently Asked Questions

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
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes