Question
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
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 ", 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;
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