Reference no: EM132915157
You will write a simple program called ring that creates a ring of N processes that send a signal round and round cnt times. The program is invoked with ./ring N leader cnt where leader is 0 when you first invoke it. The program works as follows. If the leader parameter is 0 then it knows it is the leader. It then creates (with fork-exec) a child process that has parameters leader cnt where now leader is the PID of the true leader process. The child then will create another child process with parameters leader cnt where now leader is again the PID of the true leader process. The process that eventually is created with N=1 is the last one and it does not create another child. Instead sends a SIGUSR1 to the leader to start everything. All the process suspend themselves waiting for a SIGUSR1 and then send a SIGUSR1 to the next one. At the end of the execution the leader (only) prints the cnt and the true time elapsed since the beginning of execution as a floating point number. Also write a script ring_time.sh using a for loop that runs the ring program for N=20 processes and for cnt10, 100, 1000 and 10000 signals and writes the results in the file timing.out. The format of the file timing.
out is the results of one run per line and each line contains the cnt and the time it took.
Your code should be properly commented, indented and readable. There should be a comment near the top of the file that includes a short description (3-4 lines), your name and date. Compilation should produce no warnings on the EECS Linux systems. All system calls that may return an error condition should be checked. Please keep in mind that style is very important.
Besides the code in the notes, you should read several man pages. Pages like kill(2), sigaction(2), fork(2), signal(7), errno(3), sigsuspend(2), clock_gettime(2) are good starting points.
Process starts with the main process , it creates one child, which in turn creates another child and so on until n children are created .
Thr last child doesn't create any child , instead send sigusr1 signal to the main process to start execution
After receiving the sigusr1 , it gives kill signal to its child , and suspends using sigsuspend
After that , it send signal to another child and suspends itself and so on until each process sends "cnt" number of signal
Attachment:- Simple program.rar