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>
a
<index>
s
<index>
k
<index>
p
<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>
x
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:
Solution
~geoff/CSC521/ProcessManagement/CPUsh
.
The source code and an executable for RF
is also there.