0% found this document useful (0 votes)
11 views

Operating System Assignment 6 (1)

This document outlines an assignment for adding a priority attribute to processes in the xv6 operating system. It includes steps for modifying the process structure, creating a dummy program to test process creation, and implementing a system call to change process priority. The assignment also requires updates to various files in the xv6 codebase and testing the implementation with specific commands.

Uploaded by

bmsatyam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Operating System Assignment 6 (1)

This document outlines an assignment for adding a priority attribute to processes in the xv6 operating system. It includes steps for modifying the process structure, creating a dummy program to test process creation, and implementing a system call to change process priority. The assignment also requires updates to various files in the xv6 codebase and testing the implementation with specific commands.

Uploaded by

bmsatyam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Operating System

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

ii. Assign default priority in allocproc() in proc.c


iii. Modify cps() in proc.c discussed in the last lab to include the print the
priority
*see changes on line 549, 553
Now test cps by make qemu

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

vi. Add sys_chpr() in sysproc.c

vii. Add chpr() as a system call to xv6


Follow few steps to add chpr as system call: Step 1:
Update syscall.h at line 24

Step 2: Update defs.h at line 124


Step 3: Update user.h at line 27

Step 4: Add function sys_chpr(void) in sysproc.c

Step 5: Update usys.S at line 33

Step 6: Update syscall.c


At line 107

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"

int main(int argc, char *argv[]) { int priority,


pid; if(argc < 3 ){ printf(2, "Usage: nice pid
priority\n" ); exit();
}

pid = atoi ( argv[1] ); priority = atoi (


argv[2] ); if ( priority < 0 || priority > 20 ) {
printf(2, "Invalid priority (0-20)!\n" ); exit();
}
chpr ( pid, priority ); exit();
}

Do 2 changes in Makefile as follows:

ix. Test nice


$ foo 4 & $ ps

$ nice 5 18

You might also like