Homework 204/2025

Problem Description
As illustrated in Fig.1, write a C program where a manager parent process coordinates multiple worker child processes to compute the sum of a large list of numbers. Use message queues, pipes, and signals for inter-process communication and synchronization:
  • The manager reads a large list of numbers from the input and divides it into smaller portions for each worker process.
  • Each portion is sent to a worker process using a message queue.
  • After assigning the tasks, the manager sends a signal (SIGUSR1) to notify the worker that data is ready.
  • Each worker child process computes the sum of its assigned portion. Once done, it sends the result back to the manager through an anonymous pipe and notifies the manager using a signal (SIGUSR2).
  • The manager process waits for results from all workers, combines the partial sums, and computes the total sum.
  •  The manager displays the partial sums and the final total.
Requirements
  • Use message queues to send the data portions from the manager to the workers.
  •  Use anonymous pipes to send the partial sums from the workers back to the manager.
  • Use signals for :
    •  SIGUSR1: Manager to workers, indicating that data is ready.
    •  SIGUSR2: Workers to manager, indicating that the computation is complete.
  • Include proper error handling for all functions in order to check return values of fork, pipe, msgget, msgsnd, msgrcv, etc., and exit gracefully if an error occurs.
  • The number of workers should be configurable by the user.
  • The list of numbers can either be provided as input or generated randomly.
Output of the program
  • The manager process (parent process) should display:
  • The list of numbers.
  • The partial sums computed by each worker.
  • The final total sum.
Deadline:
Students are required to bring their completed homework for consultation during the in-person session on December 10th, 2024, at 10:00 AM. Late submissions will not be accepted unless prior arrangements are made and justified due to exceptional circumstances.
Grading Criteria
The assessment of the homework will take into account several parameters, such as:
  •  Correctness: Does the program compute the correct total sum?
  • Implementation: Are message queues, pipes, and signals used correctly?
  • Error Handling: Are system calls checked for errors?
  • Synchronization: Does the program handle asynchronous behavior correctly (e.g., delays in workers)?
  •  Code Quality: Is the code well-structured, commented, and readable?

Class: 

Systèmes Répartis & Programmation Concurrente

Attach Files: