Specifications:

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:

  • Print a prompt "myshell>" and wait for your input;
  • Execute the command you type in after the prompt (e.g. ls, ps) and print a new prompt.
  • The shell understands the command "quit" as the special commands to exit.
  • If the user enters a return without input command, the shell repeats the prompt.
  • The shell understands a special command "ls_sys" that lists information of the system that were collected in assignment 1. It outputs all the information of your assignment 1.
  • The shell understands a special command "fcfs number_of_processes", which does a FCFS CPU scheduling simulation/calculation. If there is no option provided, the command assumes 5 processes.

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

Background Knowledge:

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.