Question: All codes should be written in C. Write a program that forks to create two children. The parent then sleeps and wakes up every 10

All codes should be written in C.

Write a program that forks to create two children. The parent then sleeps and wakes up every 10 seconds. Each time it wakes up it sends a signal SIGUSR1 to the first child and SIGUSR2 to the second child. After two minutes it interchanges the signal sent and sends SIGUSR2 to the first child and SIGUSR1 to the second child and continues for a further 2 minutes. The children, each, keeps two counters C1 and C2. C1 is initially 0 while C2 is initially 1. Whenever a child receives a signal SIGUSR1, it increments C1 by 1 and when it receives SIGUSR2 it multiplies C2 by 2. In either case it displays its pid and both C1 and C2.

The setitimer() call allows the programmer to reset a timer at a regular time interval. It also provides for finer time intervals than the alarm, since it can set the timer at milliseconds. Check its use and write a program that opens a file, triggers a timer every 500 ms, write in the file the total time elapsed since it started executing, every time the timer is triggered. The program should run for a total of 30 seconds.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!