Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C program about forking processes and submarines as basic as possible please! thank you Spring 2018 ECE 2220 System Programming Concepts Spring 2018 ECE 2220
C program about forking processes and submarines as basic as possible please! thank you
Spring 2018 ECE 2220 System Programming Concepts Spring 2018 ECE 2220 System Programming Concepts Lab 7 - Signals: "Base to Submarines" Objectives Child Operation Each submarine is to be initialized to have a random number between 1000 and 5000 gallons of diesel fuel, a random number between six and ten ballistic missiles, and to be a distance of zero miles from the sub base An alarm() timer is to be installed and used which: In this lab, each student is to write a single program called prog7.c which has a "base process which communicates with child processes acting as "submarines that it creates. 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 Decrements the fuel by a random number between 100 and 200 gallons each second Increments the distance from base by a random number between 5 and 10 miles every two seconds if going toward target, and decrements the distance from base by a random number between 3 and 8 miles every two seconds if returning to base. Reports the military time, fuel amount, ordinance left, and distance from base every three seconds in the appropriate terminal, e.g. Program Operation Before executing the program, the user should open four console (terminal) windows. The first terminal window will represent the base, and the other three will represent the three submarines. Parent 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 be reopened so they can be written to. Time: hh:mm:ss Sub id to base, g gallons left, b missiles left, m miles from base. If a submarine runs out of fuel before returning to base or being refueled, it should exit with a code representing an unsuccessful mission. As soon as a submarine launches its entire payload it should immediately begin returning to base. If it makes it back to base without running out of fuel, it should exit with a code representing a successful mission. Before spawning child tasks, the main function should display the date and time of the start of the mission. Input/Output It should then use fork () to spawn three child submarine tasks (which are to execute the same exact code). The program should accept the following input (where invalid commands should produce a suitable error message): ln-Orders submarine n (n=1 to 3) to launch a missile. rn-Refuels submarine n's fuel tank to a random number between 1000 and 5000 gallons. Spring 2018 ECE 2220 System Programming Concepts Spring 2018 ECE 2220 System Programming Concepts Lab 7 - Signals: "Base to Submarines" Objectives Child Operation Each submarine is to be initialized to have a random number between 1000 and 5000 gallons of diesel fuel, a random number between six and ten ballistic missiles, and to be a distance of zero miles from the sub base An alarm() timer is to be installed and used which: In this lab, each student is to write a single program called prog7.c which has a "base process which communicates with child processes acting as "submarines that it creates. 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 Decrements the fuel by a random number between 100 and 200 gallons each second Increments the distance from base by a random number between 5 and 10 miles every two seconds if going toward target, and decrements the distance from base by a random number between 3 and 8 miles every two seconds if returning to base. Reports the military time, fuel amount, ordinance left, and distance from base every three seconds in the appropriate terminal, e.g. Program Operation Before executing the program, the user should open four console (terminal) windows. The first terminal window will represent the base, and the other three will represent the three submarines. Parent 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 be reopened so they can be written to. Time: hh:mm:ss Sub id to base, g gallons left, b missiles left, m miles from base. If a submarine runs out of fuel before returning to base or being refueled, it should exit with a code representing an unsuccessful mission. As soon as a submarine launches its entire payload it should immediately begin returning to base. If it makes it back to base without running out of fuel, it should exit with a code representing a successful mission. Before spawning child tasks, the main function should display the date and time of the start of the mission. Input/Output It should then use fork () to spawn three child submarine tasks (which are to execute the same exact code). The program should accept the following input (where invalid commands should produce a suitable error message): ln-Orders submarine n (n=1 to 3) to launch a missile. rn-Refuels submarine n's fuel tank to a random number between 1000 and 5000 gallons
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started