Question

System Time Calculation Objectives of this Lab: The objective of this assignment is to get used...

System Time Calculation Objectives of this Lab: The objective of this assignment is to get used to the system time information in Linux. You will do that by writing a small program (in either C, C++ or Java) that will access system time information available from the Linux /proc directory. How to proceed with the Program: 1. Information in the /proc/uptime is available just as though the file were a regular text file. You may open the file, read out the data, save or print that data, and then close the file 2. Type the program into an editor and compile the program at the command prompt. 3. Compiling and execution is done as in Week 4 Linux project. 4. If you do not find a description of some system call by the man command, then try the Web search engine google for help (Use a Web browser to access www.google.com ). Where to look for information in (/proc) directory ? File /proc/uptime has the information for this lab. You can refer to the online manual for more information on proc (man proc). You can type the following in the command line more /proc/uptime to find the uptime of the system and the amount of time the system spending in the idle processes. Exercise : Write a program in C or C++ or Java to display the following information. 1. Time information. In this section you will print out how long the system has been up and how busy it has been. Once you have some baseline numbers printed, you will run a short program that places a load on the system. You will then take a second set of numbers and calculate the load that your program placed on the system. a. Duration of uptime # get these information from /proc/uptime b. Duration of idletime Calculating load average. Write a function that does some work (to put some load on the system) and make a note of the uptime and idletime before and after the call of the function. The following can be used as sample code for the work function. This program simple runs a math calculation a large number of times, just trying to keep the CPU busy. You can include it as a function in your overall program. Note that because you are using a math function (pow) you will need to explicitly include the math library when you compile your program, i.e., “gcc –o test test.c –lm”. (the –lm option for program compiling in C or C++.) void work() { double y; double x = 3.0; double e = 2.0; int i,j; for (i = 0; i < 5; i++) { for (j = 0; j < 400000; j++) { y = pow(x, e); } printf("Loop %d of work cycle\n", i ); // pause for one second between loops so that the work cycle takes a little time. sleep (1); // in C or C++ you will need to include the unistd.h library for this function } } The skeleton of the program (1) read file “/proc/uptime” to obtain beginTotaltime and beginIdletime (2) call work( ) to put some work into the system (7) read file “/proc/uptime” to obtain endTotaltime and endIdletime (8) Calculate the percentage of the time that CPU was busy during this program: programTotalTime = endTotalTime - beginTotalTime; programIdleTime = endIdleTime - beginIdleTime; programWorkTime = programTotalTime - programIdleTime; percentage = (programWorkTime / programTotalTime)* 100;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include <unistd.h>
#include <time.h>
using namespace std;

void work(void)
{
double y;
double x = 3.0;
double e = 2.0;
int i,j;
for(i=0; i<5; i++)
{
for(j=0; j<400000; j++)
{
y=pow(x,e);
}
printf("Loop %d of work cycle\n", i);

sleep(1);
}
}

int main(void)
{
double beginTotalTime = 0.0;
double beginIdleTime = 0.0;
double endTotalTime = 0.0;
double endIdleTime = 0.0;
double programTotalTime = 0.0;
double programIdleTime = 0.0;
double programWorkTime = 0.0;
double percentage = 0.0;

cout << "\nbeginTotaltime and beginIdletime:\n" << endl;

cout << "\nbeginTotaltime and beginIdletime:\n" << endl;
system("cat /proc/uptime");

void work(void);

cout << "\nendTotaltime and endIdletime:\n" << endl;
system("cat /proc/uptime");

programTotalTime = endTotalTime - beginIdleTime;
programIdleTime = endIdleTime - beginIdleTime;
programWorkTime = programTotalTime - programIdleTime;
percentage = (programWorkTime/programTotalTime) * 100;

cout << "\nThe program's Total Time is:   " << programTotalTime <<
endl;
cout << "The program's Idle Time is:   " << programIdleTime << endl;
cout << "The program's Work Time is:   " << programWorkTime << endl;
cout << "The percentage the CPU was busy: " << percentage << "%" << endl;

return 0;

}

Add a comment
Know the answer?
Add Answer to:
System Time Calculation Objectives of this Lab: The objective of this assignment is to get used...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In some cases, people who are not strong in Linux may need to run specific Linux...

    In some cases, people who are not strong in Linux may need to run specific Linux commands. To make this easier, you can create a menu-driven program that runs these Linux commands. Such a program allows users to execute the commands without having to actually know about how to execute them. For this scenario, create a menu-driven program that has the following options: 1. List users who are logged in (using the who command) 2. List system information (using the...

  • INFO 1111

    1.      [30] Use the Msinfo32.exe command to launch the System Information window. Browse through the different levels of information in this window and answer the following questions:a. What OS and OS version are you using?b. What is your CPU speed?c. What is your BIOS manufacturer and version?d. How much video RAM is available to your video adapter card? Explain how you got this information.e. What is the name of the driver file that manages your network adapter? Your optical drive?  2.     ...

  • Question III This question carries 20% of the marks for this assignment. Given the following mix...

    Question III This question carries 20% of the marks for this assignment. Given the following mix of tasks, task lengths and arrival times, compute the completion [5 marks and response time time from the arrival to the finish time) (5 marks for each task, along with the average response time for the FIFO. RR and SJF algorithms. Assume a time slice of 10 milliseconds and that all times are in milliseconds. You are kindly asked to provide the Gantt Chart...

  • I really need some help understaning how system verilog coding works in Cygwin I am a...

    I really need some help understaning how system verilog coding works in Cygwin I am a PC user, so I in order to have a linux version or an option to run commands I installed a program called Cygwin. This program currently allows me to run .cpp file and supposedly to run verilog (.v) and systemVerilog (.sv) file, but I am not able to or familiar with how to command call them from Cygwins terminal. I would also like to...

  • Star Database Program. This is a more sophisticated assignment, it will take longer to do. Write...

    Star Database Program. This is a more sophisticated assignment, it will take longer to do. Write a program which uses file IO, loops, and function calls. The following files are provided in pub: Assignment.cpp stars.dat solution_stars.dat solution.o when you log in the first time, make a directory for this project mkdir prog3 then copy down the files. (WARNING! This will overwrite any file in the directory named Assignment.cpp, so don't copy down Assignment.cpp if you have already done work): cp...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • Overview Writing in the C language, implement a very basic shell, called smash. In this project,...

    Overview Writing in the C language, implement a very basic shell, called smash. In this project, we will work on processing strings and using the appropriate system calls. Build System setup Before we can start writing code we need to get our build system all setup. This will involve writing a very simple makefile. You should leverage your Makefile project for this part of the assignment! Write a Makefile that provides the three targets listed below all - The default...

  • i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and...

    i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and Report Search Report host path date Execution time nnn Directories n, nnn, nnn Files nnnnnnn Sym links nnnnnnn Old files nnnnnnn Large files nnnn, nnn Graphics files nnnnnnn Executable files nnnnnnn Temporary files n, nnn, nnn TotalFileSize nnnn, nnn Introduction Lab 7 is nearly identical to Lab 2, except it is written in PowerShell, uses no UNIX/Linux tools to do its work, creates no...

  • Completion is a screenshot of the batch file showing all of the steps to create the file system s...

    Completion is a screenshot of the batch file showing all of the steps to create the file system shown below. Instructions Create a batch file clifilesystem.cmd using Notepad which performs the following steps to create the file system shown below. Also use a proper comment for each step before the command. Proof your work. Finally submit the clifilesystem.cmd file in Blackboard Figure 1. The clijfilesystem.cmd file system Work from Desktop unless using an absolute path Desktop NOS110 OS Labs Homework...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT