Question: In this assignment, you are asked to build a mini OS (shell + scheduler). We talked about a user process could be characterized alternative CPU
In this assignment, you are asked to build a mini OS (shell + scheduler).
We talked about a user process could be characterized alternative CPU and IO operations, i.e., any process consists of c1, i1, c2, i2, c3, i3, c4,...., cm, im, ... where the values of cm, im are determined by the user process behavior (implementation of the algorithm in solving different problems)
In evaluating the OS (scheduler) impact on the use processes, we only need to consider the CPU cycles of the user processes. Hence, the first task is to create (simulate) user processes with only CPU cycle, the user process could use an infinite loop to implement. When the process is scheduled to run, it prints a line of output in each iteration with the format of Process #### at iteration @@@, where #### is the process ID OS assigns, and @@@ is a counter starting from 0 to mimic the process execution progress.
The second task is to create a Shell, which is a command interpreter that is used for users to interact with the system. When you start the program, it will first print out a prompt (e.g., "shell 5500>>>"), then wait for command from the user. The following commands should be implemented:
1. x: when a user input x (X), the system should exit including shell and user processes (generated by you).
2. c #: create # processes with the fork() system call, the user processes use exec() system call to load the program defined in first task above. The number of processes should be at least 5 and no more than 10 for debugging purpose. When shell receives from the command line this #, it will create P1, P2, P3, ..., P# user processes, a smaller process number indicates it arrives the system earlier. Also the process number can be used in the shell to manage the processes. In order to mimic the ready state, you could suspend them immediately it starts (SIGSTOP) so the process' state is ready.
3. Ctrl-C handler should be implemented to suspend the currently running process and transfer the control to the scheduler (shell prompt, after this command, the user can use the commands to check the processes, and helps scheduler to restart the system)
4. l: to list the current user processes in the system including it PID, process number, and state.
5. q #: to set the time quantum to be # seconds.
6. t rr: to set the scheduler to be round robin
7. t fcfs: to set the scheduler to be first come first serve, the process number determines its arrival order.
8. k #: to terminate a process with process number #, then its state is "terminated".
9. r #: run (resume) process with process number #.
10. r all: resume to run all the processes in ready state
11. s all: suspend all the processes
Programming Tips:
1. for round robin scheduling, please use alarm() system call to implement the time quantum (10 pts)
2. use signal.h and signal () to catch and handle signals, you could use SIGKILL, SIGTERM, SIGTSTP, SIGSTOP, SIGCONT, SIGUSR1, SIGUSR2. (10 pts)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
