In this assignment, you will practice the use of fork() and several other system calls to implement a microshell in C/C++, and practice FCFS CPU scheduling algorithm.
Your shell does the following:
Example Output:
turing%>./ z1234567_project2
myshell>quit
turing%>./ z1234567_project2
myshell>ls_sys
A: ...
B: ...
…
myshell>ls
...
myshell>ps
...
myshell>hello
couldn’t execute: hello
myshell>fcfs 3
FCFS CPU scheduling simulation with 3 processes.
CPU burst: 96 ms
CPU burst: 9 ms
CPU burst: 79 ms
2
Total waiting time in the ready queue: 105 ms
Average waiting time in the ready queue: 35 ms
myshell>
myhell>fcfs
FCFS CPU scheduling simulation with 5 processes.
CPU burst: 96 ms
CPU burst: 9 ms
CPU burst: 79 ms
CPU burst: 26 ms
CPU burst: 19 ms
Total waiting time in the ready queue: 210 ms
Average waiting time in the ready queue: 42 ms
1. For the command ls_sys, you can use the code of your assignment 1. If there was any error in your assignment 1, fix them before including the code in assignment 2. (You will not be deducted again for the same errors unless it prevents you from running assignment 2.)
2. The formula to calculate the First-Come-First-Served (FCFS) CPU scheduling waiting time is given below, so that you can start working on the assignment before the related lecture on CPU scheduling:
Assume that there are n processes, arriving at the same time but in the order of p1 to pn, and each process has a CPU burst Bi, i = 1 n. Then the total waiting time for all processes using FCFS scheduling is:
W_total = B1 + (B1 + B2) + (B1 + B2 + B3) + ... + (B1 + B2 + ... Bn-1)
And the average waiting time is:
W_avg = W_total/n
The cpu bursts are randomly generated integers between 1 and 100 with seed 10. You assume the time unit is milliseconds. Note that the random numbers may change when you change the platform even with the same seed. The example output above was the result of running on turing.
3. The assignment will need several system calls for process management such as fork(), exec..(). There are six exev..() system calls available. The execlp() is probably the most straightforward for this assignment. If you choose to use execv(), execvp() or execve(), you need to build an array of pointers to the arguments. The last element of the array should be (char *) NULL. You may need strtok() to parse the command line for you. Read the manual page to understand this function.
4. The parent process needs to call waitpid() to wait for the completion of the commands.