Question: 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

  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();

}

Can someone help me to solve it, 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!