1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svetlana [45]
2 years ago
5

Your task is to write a C program that measures the latencies of various system calls. In particular, you want to know 1) the co

st of CPU mode switch by measuring a light-weight system call which does very little thing in the kernel, and 2) the cost of heavier system calls which triggers a lot of activities inside the kernel.
Computers and Technology
1 answer:
tensa zangetsu [6.8K]2 years ago
3 0

Answer and Explanation:

#include <stdio.h>

#include<fcntl.h>

#include <sys/time.h>

#include<time.h>

#define MAX 1000

int main()

{

int pid;

int i,fd ;

char c[12];

FILE *fp;

struct timeval start,end;

double time1,time2,time3;

//open file for writing

fp=fopen("output.txt","w");

 

if(!fp)

{

printf("Not able to open the file output.txt\n");

return -1;

}

for(i = 0; i < MAX ; i++)

{

gettimeofday(&start,NULL);

//invoke getpid call

system(pid = getpid());

//printf("%d\n",start.tv_usec);

}

gettimeofday(&end,NULL);

//printf("%d\n",(end.tv_usec - start.tv_usec));

time1 = ((end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0)/MAX;

 

//wtite the time taken to execute getpid to

//to get micro second , divide multiply time by 1000000 , to get nano multiply time by 1000000000

printf("getpid(): %.10f %.10f\n",time1*1000000,time1*1000000000);

fprintf(fp,"getpid():%.10f %.10f\n",time1*1000000,time1*1000000000);

//in similar way execute other two commands ,open and read

 

for(i = 0; i < MAX ; i++)

{

gettimeofday(&start,NULL);

//invoke getpid call

system(open("/dev/null", O_RDONLY ));

//printf("%d\n",start.tv_usec);

}

gettimeofday(&end,NULL);

//printf("%d\n",(end.tv_usec - start.tv_usec));

time2 = ((end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0)/MAX;

 

//wtite the time taken to execute getpid to

printf("open(): %.10f %.10f\n",time2*1000000,time2*1000000000);

fprintf(fp,"open():%.10f %.10f\n",time2*1000000,time2*1000000000);

//in similar way execute other two commands ,open and read

fd = open("/dev/dev",O_RDONLY );

//printf("fd = %d\n",fd);

for(i = 0; i < MAX ; i++)

{

gettimeofday(&start,NULL);

//invoke getpid call

system( read(fd,c,10));

//printf("%d\n",start.tv_usec);

}

gettimeofday(&end,NULL);

//printf("%d\n",(end.tv_usec - start.tv_usec));

time3 = ((end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0)/MAX;

 

//wtite the time taken to execute getpid to

printf("read(): %.10f %.10f\n",time3*1000000,time3*1000000000);

fprintf(fp,"read(): %.10f %.10f\n",time3*1000000,time3*1000000000);

}

----------------------------------------------------------

//output

//I have written output to standard output also , you can remove that

getpid(): 0.1690000000 169.0000000000    

open(): 0.1890000000 189.0000000000    

read(): 3.1300000000 3130.0000000000

------------------------------------------------------

//Makefile content

prob2.o : prob2.c    

         gcc -c  prob2.c                                                                                                                                      

prob2 : prob2.o                                                                                                                                                

       gcc -o prob2 prob2.o                                                                                                                                    

all   :                                                                                                                                                        

       gcc -o prob2 prob2.c                                                                                                                                    

clean:                                                                                                                                                          

       rm -rf prob2.o  

---------------------------------------

use

$make all

then execute as below

$./prob2

You might be interested in
Assume that you are testing the Orders database introduced in Watt (2014) - Appendix C. Discuss the problems and possible conseq
madreJ [45]

Answer:

129 \frac{2}{?} 23.4. \div 164 \times 5y1 + . \\ .00487ggh

6 0
3 years ago
Where do you place the logical test argument in an IF function formula?
Inessa [10]

Answer:

The first argument listed after IF

Explanation:

When the two variables are listed next to each other, Excel will find and calculate the correlation between them.

8 0
3 years ago
Read 2 more answers
4. What is an example of a Trans receiver? *<br> A. Pager<br> B. Wi-Fi<br> C. Telephone
Charra [1.4K]
I really think it A : pager
I hope this helps !!
8 0
2 years ago
Consider the following declaration.int[] alpha = new int[3];Which of the following input statements correctly input values into
stepladder [879]

Answer:

Option (2) i.e., Only (ii) is the correct option to the following question.

Explanation:

Here, in the following code that is written in the Java Programming Language in which they set integer data type array variable "alpha" and set its index to 3 through "new" keyword then, we get input from the user in the index 0 then, we get input from the user in the index 1 then, again we repeat this step for index 2. So, that's why the following option is correct.

Option 1 is wrong because in this option the user input only in the index 0 and this is also the wrong way to insert value in the array variable.

5 0
3 years ago
A testing lab wishes to test two experimental brans of outdoor pain long each wiil last befor fading . The testing lab makes six
Simora [160]

Answer:

The answer is "\bold{Brand \ A \ (35, 350, 18.7) \ \ Brand \ B \ (35, 50, 7.07)}"

Explanation:

Calculating the mean for brand A:

\to \bar{X_{A}}=\frac{10+60+50+30+40+20}{6}  =\frac{210}{6}=35

Calculating the Variance for brand A:

\sigma_{A}^{2}=\frac{\left ( 10-35 \right )^{2}+\left ( 60-35 \right )^{2}+\left ( 50-35 \right )^{2}+\left ( 30-35 \right )^{2}+\left ( 40-35 \right )^{2}+\left ( 20-35 \right )^{2}}{5} \\\\

     =\frac{\left ( -25 \right )^{2}+\left ( 25  \right )^{2}+\left ( 15\right )^{2}+\left ( -5 \right )^{2}+\left ( 5 \right )^{2}+\left ( 15 \right )^{2}}{5} \\\\ =\frac{625+ 625+225+25+25+225}{5} \\\\ =\frac{1750}{50}\\\\=350

Calculating the Standard deviation:

\sigma _{A}=\sqrt{\sigma _{A}^{2}}=18.7

Calculating the Mean for brand B:

\bar{X_{B}}=\frac{35+45+30+35+40+25}{6}=\frac{210}{6}=35

Calculating the Variance for brand B:

\sigma_{B} ^{2}=\frac{\left ( 35-35 \right )^{2}+\left ( 45-35 \right )^{2}+\left ( 30-35 \right )^{2}+\left ( 35-35 \right )^{2}+\left ( 40-35 \right )^{2}+\left ( 25-35 \right )^{2}}{5}

    =\frac{\left ( 0 \right )^{2}+\left ( 10 \right )^{2}+\left ( -5 \right )^{2}+\left (0 \right )^{2}+\left ( 5 \right )^{2}+\left ( -10 \right )^{2}}{5}\\\\=\frac{0+100+25+0+25+100}{5}\\\\=\frac{100+25+25+100}{5}\\\\=\frac{250}{5}\\\\=50

 Calculating the Standard deviation:  

\sigma _{B}=\sqrt{\sigma _{B}^{2}}=7.07

4 0
3 years ago
Other questions:
  • You work for a large enterprise company that handles time-sensitive information. Your supervisor has asked that you set up a con
    8·1 answer
  • Aria has modified the hard disk that hosts the operating system by using the fdisk command. The fdisk command indicates that the
    8·1 answer
  • Which best describes the benefits of renting a home?
    10·2 answers
  • For this lab, you will work on a simple GUI application. The starting point for your work consists of four files (TextCollage, D
    5·1 answer
  • Should organizations fear websites where consumers post negative messages about products or services? What actions can companies
    12·1 answer
  • The term ____ means that a public information network such as an Internet service provider (ISP) should treat all users, all pla
    9·1 answer
  • What are five types of applications you can create in Visual Basic 2017?
    12·2 answers
  • How do i delete cookies on a chromebook?
    8·1 answer
  • What is the half of 3/18
    6·1 answer
  • PLEASE HELP!
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!