Question: Create a ps.c and nice.c file in which the cps and chpr functions will be called respectively. #include types.h #include stat.h #include user.h #include fcntl.h

  1. Create a ps.c and nice.c file in which the cps and chpr functions will be called respectively.

#include "types.h"

#include "stat.h"

#include "user.h"

#include "fcntl.h"

int main(void){

cps();

exit();

}

#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 ");

exit();

}

pid = atoi(argv[1]);

priority = atoi(argv[2]);

if (priority < 0 || priority > 20){

printf(2,"Invalid priority (0-20)! ");

exit();

}

chpr(pid, priority);

exit();

}

  1. The work on the system calls is now done. Now work on the process priority assignment. For this, define the default priority of a process in the allocproc function in the proc.c file.

As per the class discussions, the higher the number indicates lower priority of the process.

//Add this under the "found:" part of the allocproc function in proc.c

found:

p->state = EMBRYO;

p->pid = nextpid++;

p->priority = 10; //Default Priority of a process is set to be 10

  1. The child process is now expected to have higher priority than the parent process. The priority of child process needs to be changed when it is created. For this, make the changes in exec.c file.

/* Add this above the "bad:" part in the exec.c file where all other child process attributes are mentioned */

curproc->priority = 2; //Giving child process default priority of 2

  1. Create a c program which creates a number of child process as mentioned by the user and consumes CPU time for testing the system calls and scheduling. Create a new file dummy_func.c(dummy program) and write the following code:

#include "types.h"

#include "stat.h"

#include "user.h"

#include "fcntl.h"

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

int pid;

int k, n;

int x, z;

if(argc < 2)

n = 1; //Default

else

n = atoi(argv[1]);

if (n < 0 ||n > 20)

n = 2;

x = 0;

pid = 0;

for ( k = 0; k < n; k++ ) {

pid = fork ();

if ( pid < 0 ) {

printf(1, "%d failed in fork! ", getpid());

} else if (pid > 0) {

// parent

printf(1, "Parent %d creating child %d ",getpid(), pid);

wait();

}

else{

printf(1,"Child %d created ",getpid());

for(z = 0; z < 4000000000; z+=1)

x = x + 3.14*89.64; //Useless calculation to consume CPU Time

break;

}

}

exit();

}

  1. Make the appropriate changes in the Makefile. In Makefile, under UPROGS, add the following:

_ps\ _dummy_func\ _nice\

  1. In the EXTRAS section of the Makefile, add nice.c, dummy_func.c and ps.c

can someone help me to solve it using ubuntu, please? My laptop is broken please help me?

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!