Question: Please provide all the code. Donot miss anything Purpose In the previous project we created a utility that just launched user processes with various limits
Please provide all the code. Donot miss anything
Purpose
In the previous project we created a utility that just launched user processes with various limits In this project we will be adding functionality that we will use in later on projects.
Task
As in the previous project, you will have two executables, oss and worker. The oss executable will be launching workers. However, we have a few more details.
Our main executable oss will now be maintaining a "simulated system clock" in shared memory. This system clock is not tied to the main clock of the system, but instead done separately. The clock consists of two separate integers one storing seconds, the other nanoseconds in shared memory, both of which are initialized to zero. This system clock must be accessible by the children, so it is required to be in shared memory. The children will not be modifying this clock for this assignment, but they will need to look at it
In addition to this, oss will also maintain a process table consisting of Process Control Blocks, one for each process This process table does not need to be in shared memory. The first thing it should keep track of is the PID of the child process, as well as the time right before oss does a fork to launch that child process based on our own simulated clock It should also contain an entry for if this entry in the process table is empty ie: not being used I suggest making your process table an array of structs of PCBs for example:
struct PCB
int occupied; either true or false
pidt pid; process id of this child
int startSeconds; time when it was forked
int startNano; time when it was forked
;
struct PCB processtable;
Note that your process table is limited in size and so should reuse old entries. That is if the process occupying entry finishes, then the next time you go to launch a process, it should go in that spot. When oss detects that a process has terminated, it can clear out that entry and set its occupied to indicating that it is now a free slot.
worker, the children
The worker takes in two command line arguments, this time corresponding to how many seconds and nanoseconds it should decide to stay around in the system. For example, if you were running it directly you might call it like:
worker
The worker will then attach to shared memory and examine our simulated system clock. It will then figure out what time it should terminate by adding up the system clock time and the time passed to it in our simulated system clock, not actual time This is when the process should decide to leave the system and terminate.
For example, if the system clock was showing seconds and nanoseconds and the worker was passed and as above, the target time to terminate in the system would be seconds and nanoseconds. The worker will then go into a loop, constantly checking the system clock to see if this time has passed. If it ever looks at the system clock and sees values over the ones when it should terminate, it should output some information and then terminate.
So what output should the worker send? Upon starting up it should output the following information:
WORKER PID: PPID: SysClockS: SysclockNano: TermTimeS: TermTimeNano: Just Starting
The worker should then go into a loop, checking for its time to expire IT SHOULD NOT DO A SLEEP It should also do some periodic output. Everytime it notices that the seconds have changed, it should output a message like:
WORKER PID: PPID: SysclockS: SysclockNano: TermTimeS: TermTimeNano: seconds have passed since starting
and then one second later it would output:
WORKER PID: PPID: SysClockS: SysclockNano: TermTimes: TermTimeNano: seconds have passed since starting
Once its time has elapsed, it would send out one final message:
WORKER PID: PPID: SysClockS: SysclockNano: TermTimeS: TermTimeNano: Terminating
oss, the parent
The task of oss is to launch a certain number of worker processes with particular parameters. These numbers are determined by its own command line arguments.
Your solution will be invoked using the following command:
oss hn procs simult timelimitForChildreni intervalInMsToLaunchChildren
While the first two parameters are similar to the previous project, the t parameter is different. It now stands for the bound of time that a child process will be launched for. So for example, if it is called with t then when calling worker processes, it should call them with a time interval randomly between second and seconds with nanoseconds also random
The i parameter is new. This specifies how often you should launch a child based on the system clock For example, if i is passed, then your system would launch a child no more than once every milliseconds. This is set to allow user processes to slowly go into the system, rather than flood
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
