ECE 272 Organization of Computers Spring 2022ECE 2220 System Programming Concepts3 of 4 Lab 7 – Signals and Threads Objectives In this lab, each student is to write a single program called p7.c...

1 answer below »
In C-Language


ECE 272 Organization of Computers Spring 2022ECE 2220 System Programming Concepts3 of 4 Lab 7 – Signals and Threads Objectives In this lab, each student is to write a single program called p7.c which has a parent process which communicates with three child processes it spawns. The student should exhibit a working knowledge of: · Handling processes by use of fork(), getpid()and wait() · Handling signals by use of signal(), alarm()and kill() · Using System Time Functions and generating random numbers. · Opening and accessing a console window buffer Program Operation Before executing the program, the user should open four console (terminal) windows. The first terminal window will represent the parent process and the other three will represent three child process. Input The main program represents a gardener who must take care of their three plants. The person which runs as the parent process will accept the following commands: · fn – “Gardener” “feeds” plant with n with fertilizer. · wn – “Gardener” “waters” plant n with water. · s – “Gardener” lists the id’s of all plants planted and alive (running). · q – Exit the program. Invalid commands should produce a suitable error message. Parent and Children Operation The first action of the program’s main loop is to discover how many terminals are open by trying to open all possible terminal number buffers (e.g. /dev/pts/1, /dev/pts/2 etc…) as a read only file. Those that are open should be stored so that the first four found can then be “opened” and written to. Before spawning child tasks, the main function should display the date and time of the start of the program. The parent process should then use fork() to spawn three child processes which all execute the same code. Each “plant” should start out with 10 g of fertilizer and 1 L of water when “planted.” The plant process should notify the parent it has been planted by printing out the following symbol in its terminal. \|/ --|-- ------------------------- Upon creation, each “plant” should execute a simple loop which counts fertilizer and water downward from ten grams and one liter at a random rate. Every second each plant should subtract a random value of fertilizer uniformly distributed between 1000 and 3000 mg. Also, every second each plant should subtract a random value of water uniformly distributed between 100 and 300 mL. Furthermore, whenever a plant has less than 5 grams of fertilizer or 500 mL of water, it should notify the parent process by printing out a message that it needs more water and/or fertilizer. Every five seconds (one “day”) the plant should “grow” one row by adding another part of its stem displayed as | | as shown below: Day 1 \|/ --|-- | | ------------------------- Day 2 \|/ --|-- | | | | ------------------------- Day 3 \|/ --|-- | | | | | | ------------------------- Whenever a plant has grown to ten rows high, it will notify the parent process it is ready to be sold and terminate. If a plant’s water or fertilize level ever reaches zero for five seconds, then the plant should notify the parent process that it has died and then terminate. The parent process (gardener) must maintain a list of process IDs of its plants. Given the status command, the parent process should list each plant processes index and process ID’s that are running. Plant 1: 589314 Plant 3: 589316 Given the feed n command, the gardener should send the signal SIGUSR1 to the plant with process ID corresponding to the index n. Upon receiving the signal, the plant should add 2000 mg of fertilizer to its current level. Given the water n command, the base process should send the signal SIGUSR2 to plant with process ID = id. corresponding to index n. Upon receiving the signal SIGUSR2, a plant should add 200 mL of water to its current water level. Whenever a plant’s water level goes below 500 mL or fertilizer drops below 5000 mg it should print the message “Plant n almost out of water” or “Plant n almost out of fertilizer”, respectively. Upon receiving the signal SIGUSR1 or SIGUSR2 a plant should print out the data: Plant n: id – x mg of fertilizer left Y mL of water left. Where n is the plant index (1 to 3) and id is the plane’s process ID. Further Considerations The program should be structured neatly, easily readable, and well commented. Code should be modularized with functions, logically structured, and written to perform efficiently as possible. Furthermore, variable and function names should be such that the software is as “self-commenting” as possible. The main function should mainly contain only functions called to complete the separate tasks given. Creation and Submission Work must be completed by each individual student, and only that student. Students must not use code from another student or copied from a book or internet source. Students must not allow other students to copy from their code or make it possible for students to do so by making their code available to be copied. Sharing of code will not be tolerated and will be tested for. Any such act of cheating will result in failing the class and may result in dismissal from the University. Use the following line to compile your program gcc -Wall -g p7.c -o p7 The code you submit must compile using the –Wall flag and no compiler errors or warnings should be printed. To receive credit for this assignment the code must compile and at a minimum perform some required function. Code that does not compile or crashes before performing some required function will not be accepted or graded. All students must do a final check on one of the CES Ubuntu machines to verify that gcc using Ubuntu shows no warning messages before submitting the project. Submit your program on Canvas by midnight Friday, May 6th.
Answered 7 days AfterApr 28, 2022

Answer To: ECE 272 Organization of Computers Spring 2022ECE 2220 System Programming Concepts3 of 4 Lab 7 –...

Nidhi answered on May 06 2022
99 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here