• edited by
65 views
0 0 votes

For all the questions below, the term CPU utilization means the percent of time the CPU is busy, over a long period of time. For all the questions below, assume that we are only considering a single core CPU.

Consider the following program (read the comments to understand some details). What is the CPU utilization of the following program when it is run?
$\_\_\_\_$ Round up your answer to the closest integer in $[0,100]$. Assume that the function useCPU() uses the CPU for $100$ ms on the machine on which the program is executing.

#include<iostream>
#include<cstdlib>
#include<unistd.h>
#include<sys/time.h>
using namespace std;
void useCPU () {
    int i;
        double z;
        for (i = 0; i < 1200000; i++)
            z = (double) rand ()/ (double)rand();
}

int main () {
    while (1) {
        struct timeval start, end;
        useCPU(); //uses CPU for 100 ms
        usleep (400000); // sleeps for 400 ms (400000 microseconds)
    }
}

Please log in or register to answer this question.

Position:
Show:

Related questions

0 0 votes
0 0 answers
150
150 views
admin asked Jan 17
150 views
Consider the following lex script.%% a { printf("Token 1 (Lexeme %s)\n",yytext); } a(b|cd)*b { printf("Token 2 (Lexeme %s)\n",yytext); } a(b|cd)*cd { printf("Token 3 (Lex...
0 0 votes
0 0 answers
98
98 views
admin asked Jan 17
98 views
Consider the following grammar which generates if statements. For brevity, other statements are represented by $a$ and expressions derive $b$, with both being treated as ...
0 0 votes
0 0 answers
96
96 views
admin asked Jan 17
96 views
Consider the following syntax directed definition (SDD) for generating $3$-address code for field accesses in structure variables in C/C++. It uses the following attribut...
0 0 votes
0 0 answers
120
120 views
admin asked Jan 17
120 views
Consider the following program for computing factorial of a number and the given activation record structure.\[\begin{array}{|l|l|}\hline\text{int main()} & \text{int fac...