În desfăşurare

Semaphores and Message Passing( C programming)

Problem: Write a program to compute the summation of n integers in each of the following ways and assess their performance. Assume that n is a power of 2.

1. Partition the n integers into n/2 pairs. Use n/2 processes to add together each pair of integers resulting into n/2 integers. Repeat the method on the n/2 integers and continue until the final result is obtained. (This is a binary tree algorithm.)

2. Divide the n integers into n/ log n groups of log n numbers each. Use n/ log n processes, each adding the numbers in one group sequentially. Then add the n/ log n results using method 1.

Structure the integers into a file, one integer per line.

The main program will set up shared memory to read integers, set up a signal handler, and then, read all integers into shared memory from specified file. Since you do not know the number of integers to read, you may have to run two passes over the data file to find the number of integers and to actually read in the integers. Then, the main program will fork off

child processes who will create more children as needed. The children will test the index assigned to them, perform the computation, and write the result in place of the first integer. Further, the child process will also update a log file, named adder_log to say what has been done. You will use semaphores to protect the critical resources – the log file.

Make sure you never have more than 20 processes in the system at any time. Add the pid of the child to the file as comment to the file. The preferred output format is:

PID Index Size

The child process will be execed by the command

bin_adder xx yy

where xx is the index number starting the list of integers to be added in shared memory and yy is the number of integers to be added.

If a process starts to execute code to enter the critical section, it must print a message to that effect on stderr. It will be a good idea to include the time when that happens. Also, indicate the time on stderr when the process actually enters and exits the critical section. Within the critical section, wait for 1 second before you write into the file, and then, wait for another 1 second before leaving the critical section. For each child process, tweak the code so that the process requests and enters the critical section at most five times.

The code for each child process should use the following template:

for ( i = 0; i < 5; i++ )

{

sleep for random amount of time (between 0 and 3 seconds);

wait for semaphore;

/* Critical section */

signal semaphore;

}

Implementation

You will be required to create separate bin_adder processes from your main process. That is, the main process will just

spawn the child processes and wait for them to finish. The main process also sets a timer at the start of computation to

100 seconds. If computation has not finished by this time, the main process kills all the spawned processes and then exits.

Make sure that you print appropriate message(s).

In addition, the main process should print a message when an interrupt signal (^C) is received. All the children should be killed as a result. All other signals are ignored. Make sure that the processes handle multiple interrupts correctly. As a precaution, add this feature only after your program is well debugged.

The code for main and child processes should be compiled separately and the executables be called master and bin_adder.

Make sure that you do not use absolute path for the child processes.

Other points to remember: You are required to use fork, exec (or one of its variants), wait, and exit to manage multiple processes. Use shmctl suite of calls for shared memory allocation. Also make sure that you do not have more than twenty processes in the system at any time. You can do this by keeping a counter in master that gets incremented by fork and

decremented by wait.

What to handin: Handin an electronic copy of all the sources, README, Makefile(s), and results.

Aptitudini: Programare C, Linux, UNIX

Vezi mai multe: programming problem word combinations, aspnet commerce programming problem design solution chm, approaching programming problem, message passing freelance 2000, programming unlimited number requests, hardware implementation message passing memory verilog, rmi source code client server message passing, udp transmission tcp message passing client server, matlab code linear programming problem, can fix facebook programming problem, project dot net linear programming problem, message passing, android aspnet c programming mvc php, android aspnet c# programming mvc, php,, arm microcontroller c programming, basic c programming, c# programming from problem analysis to program design, c# programming from problem analysis to program design pdf, c++ programming problem

Despre angajator:
( 4 recenzii ) Saint Louis, United States

ID Proiect: #24218370

4 freelanceri licitează în medie 130$ pentru acest proiect

iridescent2x15

Hi I have done many c and c++ projects. Kindly contact to discuss more details about your project in chat. Thank you

%bids___i_sum_sub_35%%project_currencyDetails_sign_sub_36% USD în 7 zile
(53 recenzii)
6.2
koustav2006

HI.. I am proficient in programming IPC in C/C++ for Unix/Linux macine unse gcc/g++ compiler and can help you write the n summation problem using processes and semaphores as per given specs.

%bids___i_sum_sub_35%%project_currencyDetails_sign_sub_36% USD în 2 zile
(155 recenzii)
6.3
Softeria

I have done MS Comp Software Engineering. I have studied Advance Software Engineering, Advance Requirement Engineering courses and Software System Design .I have good experience of UML diagrams, DFD, ERD, Class diagr Mai multe

%bids___i_sum_sub_35%%project_currencyDetails_sign_sub_36% USD în 3 zile
(12 recenzii)
4.8
casper70

Hi, how are you? I can help you to do this project. I am familiar with c/c++. Let me know if you have interests on my proposal. Thanks.

%bids___i_sum_sub_35%%project_currencyDetails_sign_sub_36% USD în 7 zile
(2 recenzii)
2.7