Operating Systems: Process Management Assignment


Multitasking provides a mechanism by which a user can get the impression that many processes are running simultaneously. If there is IO in any of the processes, then this IO may be done genuinely in parallel with computation. However, computation parallelism is limited to the number of CPUs in the machine, often only one (i.e., no computation parallelism occurs). For a user who has multiple computation intensive processes to run, multitasking therefore gains nothing, and in fact may slow progress due to the overhead of multitasking. Such a user may prefer to have direct control over the execution of the tasks, so that the CPU may be dedicated to any subset of the processes.

Write a control tool for the lab UNIX environment that allows the user direct control over which processes are running (multitasking under UNIX) at any point in time. The tool must be interactive, providing the following commands (you may assume that users will enter correctly formatted commands):

l <executable program file name and parameters>
Load the executable program into a process, but do not start it running. It can be activated later. Each process is assigned an integer index, by which it is referred to in other commands.
a <index>
Activate the execution of process <index>.
s <index>
Suspend the execution of process <index>. It can be activated again later.
k <index>
Kill the execution of process <index>.
p
List the processes currently loaded. Each line gives information about one loaded program, in the format:
<index> <UNIX PID> <status> <executable file name and parameters>
where the <status> is one of R (running) or S (suspended). A final line should specify any delayed command (see below), in the format:
Delayed <delayed command>
d <delay time> <command>
In <delay time> wall clock seconds, execute the command. The command may be any of the above. Only one delayed command may be pending at any time, and omitting the <delay time> and <command> removes any pending delayed command.
x
Exit. Any remaining processes must be killed first.
Here's a sample run. RF is a program that recursively computes the Nth Fibonacci number (i.e., it's a compute intensive task). The comments starting with // are not part of the normal output; I have added these in by hand to explain what's going on.
MyUNIXPrompt> CPUsh
                                 //----Test list, load, activate, end
p                                      //----Get a process list - nothing
l RF 38                                //----Load RF with parameter 38
ACTION: Process 0 loaded               //----CPUsh reports load is done
p                                      //----Get a process list
 0 74990 S RF 38                       //----RF 38 is process 0 with UNIX PID 74990, and is suspended
a 0                                    //----Activate process 0
ACTION: Process 0 activated            //----CPUsh reports activation
Recursively computing the 38th Fibonacci number    //----Output from RF 38
p                                      //----Get a process list
 0 74990 R RF 38                       //----Process 0 is now running
The 38th Fibonacci number is 24157817  //----Output from RF 38 as it completes
ACTION: Process 0 ended                //----CPUsh reports end of process 0
p                                      //----Get a process list - nothing
                                 //----Test suspend, activate
l RF 40                                //----Load RF with parameter 40
ACTION: Process 0 loaded               //----CPUsh reports load is done
a 0                                    //----Activate process 0
Recursively computing the 40th Fibonacci number    //----Output from RF 40
ACTION: Process 0 activated            //----CPUsh reports activation
p                                      //----Get a process list
 0 75018 R RF 40                       //----RF 40 is process 0 with UNIX PID 75018, and is running
s 0                                    //----Suspend process 0
ACTION: Process 0 suspended            //----CPUsh reports suspension
p                                      //----Get a process list
 0 75018 S RF 40                       //----RF 40 is process 0 with UNIX PID 75018, and is suspended
a 0                                    //----Activate process 0
ACTION: Process 0 activated            //----CPUsh reports activation
p                                      //----Get a process list
 0 75018 R RF 40                       //----RF 40 is process 0 with UNIX PID 75018, and is running
The 40th Fibonacci number is 63245986  //----Output from RF 40 as it completes
ACTION: Process 0 ended                //----CPUsh reports end of process 0
p                                      //----Get a process list - nothing
                                 //----Test double load, activate, suspend, kill
l RF 38                                //----Load RF with parameter 38
ACTION: Process 0 loaded               //----CPUsh reports load is done
l RF 40                                //----Load RF with parameter 40
ACTION: Process 1 loaded               //----CPUsh reports load is done
p                                      //----Get a process list
 0 75002 S RF 38                       //----RF 38 is process 0 with UNIX PID 75002, and is suspended
 1 75003 S RF 40                       //----RF 40 is process 1 with UNIX PID 75003, and is suspended
a 0                                    //----Activate process 0
Recursively computing the 38th Fibonacci number    //----Output from RF 38
ACTION: Process 0 activated            //----CPUsh reports activation
p                                      //----Get a process list
 0 75002 R RF 38                       //----RF 38 is process 0 with UNIX PID 75002, and is running
 1 75003 S RF 40                       //----RF 40 is process 1 with UNIX PID 75003, and is suspended
a 1                                    //----Activate process 1
Recursively computing the 40th Fibonacci number    //----Output from RF 40
ACTION: Process 1 activated            //----CPUsh reports activation
s 0                                    //----Suspend process 0
ACTION: Process 0 suspended            //----CPUsh reports suspension
p                                      //----Get a process list
 0 75002 S RF 38                       //----RF 38 is process 0 with UNIX PID 75002, and is suspended
 1 75003 R RF 40                       //----RF 40 is process 1 with UNIX PID 75003, and is running
k 1                                    //----Kill process 1
ACTION: Process 1 ended                //----CPUsh reports end of process 1
p                                      //----Get a process list
 0 75002 S RF 38                       //----RF 38 is process 0 with UNIX PID 75002, and is suspended
k 0                                    //----Kill process 0
ACTION: Process 0 ended                //----CPUsh reports end of process 0
p                                      //----Get a process list - nothing
                                 //----Test delayed activation
l RF 38                                //----Load RF with parameter 38
ACTION: Process 0 loaded               //----CPUsh reports load is done
d 3 a 0                                //----Delay 3 seconds until a 0
ACTION: Delay 3 until doing a 0        //----CPUsh reports delayed command
p                                      //----Get a process list
 0 75073 S RF 38                       //----RF 38 is process 0 with UNIX PID 75073, and is suspended
Delayed a 0                            //----Command a 0 is delayed
ACTION: Doing delayed command a 0      //----Delayed command a 0 is done
Recursively computing the 38th Fibonacci number    //----Output from RF 38
ACTION: Process 0 activated            //----CPUsh reports activation
The 38th Fibonacci number is 24157817  //----Output from RF 38 as it completes
ACTION: Process 0 ended                //----CPUsh reports end of process 0
                                 //----Test delayed kill
l RF 40                                //----Load RF with parameter 40
ACTION: Process 0 loaded               //----CPUsh reports load is done
d 5 k 0                                //----Delay 5 seconds until k 0
ACTION: Delay 5 until doing k 0        //----CPUsh reports delayed command
a 0                                    //----Activate process 0
Recursively computing the 40th Fibonacci number    //----Output from RF 40
ACTION: Process 0 activated            //----CPUsh reports activation
ACTION: Doing delayed command k 0      //----Delayed command k 0 is done
ACTION: Process 0 ended                //----CPUsh reports end of process 0
p                                      //----Get a process list - nothing
                                 //----Test exit
x                                      //----Exit
Goodbye                                //----CPUsh reports its termination

You must submit your solution files using the submit2 program:

    ~csc521/bin/submit2 csc521 ProcessManagers <your file names> 
by 6am on 18th October. Your program will be tested using the above command sequence, and a few others. Your program will be assessed on: It is worth 15% of the subject's assessment. Please review the policies on assessment in the administration document.

Solution