LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-06-2009, 03:18 PM   #1
sfskseg32
LQ Newbie
 
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
System uptime


Hello,

I have a hw assignment to obtain the system totaltime and idletime, perform a calculation, obtain totaltime and uptime again, and calculate the percentage of time that the cpu was busy during that time.

I know how to obtain the uptime and it is a file of the totaltime and idletime, but I don't know how to store those seperately. So far my prog looks like this:
Code:
#include <iostream>
#include <fstream>
using namespace std;

void work()
{
double y;
double x=12340;
double z=98760;
for(long j=0;j<100000;j++)
{
for(long j=0;j<100000;j++)
{
y=x*z;
}
}
}

int main()
{
cout << "\nTotaltime and Idletime:\n" << endl;
system("cat /proc/uptime");
work();
cout << "\nTotaltime and Idletime:\n" << endl;
system("cat /proc/uptime");
return 0;
//HERE IS WHERE I WILL PERFORM CALCS
}
I need to store the 4 times and then perform the calculations. How do I store the times?

thanks
j
 
Old 12-06-2009, 05:22 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Your real question is "how to read /proc/uptime".

One possible answer: substitute "popen()" for "system (cat SOMEFILE)". Then you can "fread()" or "fgets()" from /proc/uptime.

An even better possibility: just "fopen()" /proc/update. Try it!

IMHO ..PSM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Way to force a specific value for system uptime? soliax Linux - Kernel 8 09-10-2008 12:18 AM
'Uptime' system load averages miknight Linux - General 14 01-30-2008 02:28 PM
System Uptime mindjet Suse/Novell 7 05-15-2006 02:35 AM
How to get System UpTime using C program ? D M Mehta Programming 1 02-25-2004 01:47 AM
uptime system call ?? Agent007 Programming 4 01-10-2004 04:31 AM


All times are GMT -5. The time now is 08:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration