Operating System Assignment 6 (1)
Operating System Assignment 6 (1)
Assignment – 6
Name: Satyam Dwivedi
Reg. no.: 2020CA081
Question 1. Adding Process Priority: In this lab, we will walk you through the steps
of adding a priority attribute to a process in xv6 andchanging its value. We assign a
process with a value between 0 and 20, the smaller the value, thehigher the priority.
The default value is 10.
i. Add priority to struct proc in proc.h
iv. Write a dummy program named foo.c that creates some child processes
and consumes some computing time
#include "types.h"
#include "stat.h"
#include "user.h" #include "fcntl.h" int
main(int argc, char *argv[]) { int k, n, id;
double x = 0, z; if(argc < 2 ) n = 1;
//default value else n = atoi ( argv[1] );
//from command line
if ( n < 0 || n > 20 ) n = 2; x = 0; id = 0; for
( k = 0; k < n; k++ ) { id = fork (); if ( id <
0){ printf(1, "%d failed in fork!\n", getpid() );
} else if ( id > 0 ) { //parent printf(1, "Parent
%d creating child %d\n", getpid(), id ); wait ();
} else
{ // child
printf(1, "Child %d created\n",getpid() ); for ( z = 0; z < 8000000.0; z +=
0.01 ) x = x + 3.14 * 89.64; // useless calculations to consume CPU time
break;
}
} exit();
}
*update MakeFile by adding _foo\ and foo.c\
v. Add the function chpr() (meaning change priority ) in proc.c
viii. Create the user file nice.c with which calls chpr
Create a file nice.c
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
$ nice 5 18