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
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started