Question: In this assignment, you are asked to build a mini OS ( shell + scheduler ) . We talked about a user process could be

In this assignment, you are asked to build a mini OS (shell + scheduler).
We talked about a user process could be characterized by 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 assigned by the OS, and @@@ is a counter starting from 0 to mimic the execution progress. of the process.
A sample implementation of such a process could be as follows:
int main(int argc, char* argv[]){
//initialization and other necessary operations
// signal handler registration: for example, you could define my_sig_handler(), then call from here
signal(SIGINT, my_sig_handler);
while(1){
printf("Process %d at iteration %d
", mypid, count++);
sleep(1); // you could also use usleep() with specified high resolution time length
}
}
The second task is to create a Shell, which is a command interpreter that is used for users to interact with the system. When Shell starts, it will first print out a prompt (e.g., "shell 5500>>>"), then wait for command inputs from the user.
For the shell implementation, you can envision it as an ongoing process that patiently awaits user input, interprets the provided commands, and takes appropriate actions accordingly. A sample code could be as follows:
while(1){
read_size = getline(&buffer, &size, stdin);
//handling on read_size;
// interprets the buffer to get the command and its parameters...
switch(command){
case 'x':
//handling 'x' command
break;
case 'l':
// handling 'l' command
break;
etc... for other commands
}
The following commands should be implemented:
1. x: when a user inputs x (X), your Shell "system" should exit including the shell and all the processes created through/by the Shell.
2. c n: create n (a natural number) 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 n should be at least 5 and no more than 10 for debugging purpose. The shell creates users processes P1, P2, P3,..., Pn, a smaller process number (the subscript of Pi ,where 1=i=n) indicates it arrives at 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 when 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 interact with system through running use the commands, such as checking to check the status of processes, configuring scheduling algorithms, etc., after that the 'scheduler' can schedule another process to run).
4. l: to list the current user processes in the system including it PID (underlying process ID from the host OS - Ubuntu), process number, and state.
5. s rr q: to set the scheduler to be round robin with time quantum of q time units (seconds).
6. s fcfs: to set the scheduler to be first come first serve, the process number determines its arrival order.
7. k #: to kill a process with process number #, then state of the process # is "terminated".
8. r #: resume process with process number #, which was suspended by Ctrl-C, the process # is put back into ready queue and enables the scheduler
9. r all: run all the processes after configurations (e.g., specifying the scheduling algorithms), which essentially enables your scheduler.
 In this assignment, you are asked to build a mini OS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!