-
Reading /proc
Hey everyone,
i want to read in the output of /proc/loadavg. Because this should be handled as a normal file, i thought i could do it this way (open the files, not yet read them):
Code:
char* file = "/proc/loadavg";
ofstream output;
output.open(file,ios_base::in);
if(output.good()){
// was able to open file
cout << "opened\n";
}
output.close();
if(output.good()){
cout << "closed";
}
But it seems like output.good() and output.close() dont return true, because no output is generated!
I already checked the rights.
When I create a text file in my home folder and open it with that code snipped, it works well.
Any ideas? Google and the board search did not provide any useful results.
Thank you!
crisis
-
I take it "cat /proc/loadavg" works?
Can you do "strace cat /proc/loadavg 2> trace.txt"
Then "strace myprog 2> trace2.txt"
Compare the open statements for /proc/loadavg and see if there is any difference.
--
Mats
-
> ofstream output;
> output.open(file,ios_base::in);
You're opening an OUTPUT file for INPUT
What about this seems strange to you?
-
thank you both!
this works:
Code:
ifstream rawavg("/proc/loadavg");
string buffer;
getline(rawavg,buffer);
cout << buffer << "\n";
rawavg.close();