Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

YOUR UNIQUE ANSWER IS APPRECIATED, THANKS! Task ----------------------------------- As in the previous project, you will have two executables, oss and worker. The oss executable will

YOUR UNIQUE ANSWER IS APPRECIATED, THANKS!

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 pid_t pid; // process id of this child int startSeconds; // time when it was forked int startNano; // time when it was forked }; struct PCB processTable[20];

-----------------------------------------------

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 5 500000 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. This is when the process should decide to leave the system and terminate.

For example, if the system clock was showing 6 seconds and 100 nanoseconds and the worker was passed 5 and 500000 as above, the target time to terminate in the system would be 11 seconds and 500100 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:6577 PPID:6576 SysClockS: 5 SysclockNano: 1000 TermTimeS: 11 TermTimeNano: 500100 --Just Starting The worker should then go into a loop, checking for its time to expire. It should also do some periodic output. Everytime it notices that the seconds have changed, it should output a message like: WORKER PID:6577 PPID:6576 SysClockS: 6 SysclockNano: 45000000 TermTimeS: 11 TermTimeNano: 500100 --1 seconds have passed since starting and then one second later it would output: WORKER PID:6577 PPID:6576 SysClockS: 7 SysclockNano: 500000 TermTimeS: 11 TermTimeNano: 500100 --2 seconds have passed since starting Once its time has elapsed, it would send out one final message: WORKER PID:6577 PPID:6576 SysClockS: 11 SysclockNano: 700000 TermTimeS: 11 TermTimeNano: 500100 --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 [-h] [-n proc] [-s simul] [-t timelimit] 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 7, then when calling worker processes, it should call them with a time interval randomly between 1 second and 7 seconds (with nanoseconds also random). When started, oss will initialize the system clock and then go into a loop and start doing a fork() and then an exec() call to launch worker processes. However, it should only do this up to simul number of times. So if called with a -s of 3, we would launch no more than 3 initially. oss should make sure to update the process table with information as it is launching user processes. This seems close to what we did before, however, will not be doing wait() calls as before. Instead, oss() will be going into a loop, incrementing the clock and then constantly checking to see if a child has terminated. Pseudocode for this loop is below: while (stillChildrenToLaunch) { incrementClock(); Every half a second, output the process table to the screen checkIfChildHasTerminated();

if (childHasTerminated) { updatePCBOfTerminatedChild; possiblyLaunchNewChild(obeying process limits) } }

The check to see if a child has terminated should be done with a nonblocking wait() call. This can be done with code along the lines of: int pid = waitpid(-1, &status, WNOHANG); waitpid will return 0 if no child processes have terminated and will return the pid of the child if one has terminated. The output of oss should consist of, every half a second in our simulated system, outputting the entire process table in a nice format. For example: OSS PID:6576 SysClockS: 7 SysclockNano: 500000 Process Table: Entry Occupied PID StartS StartN 0 1 6577 5 500000 1 0 0 0 0 2 0 0 0 0 ... 19 0 0 0 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions