?
Solved

Real time stats!

Posted on 2003-03-11
8
Medium Priority
?
219 Views
Last Modified: 2010-08-05
Hello everyone!!

I'm currently at writing a C software that will do many operation per min and I would like it to show real time stats (or at least update every minute, so I can have a operations/min stat). the C soft runs in linux, in a console.. so i don't really know how I could have the stats to show.. what I thought was to write the elasped time and the number of operation in a file every min or so, and then make a web interface that would read this file and display the status.. but I'm far away from being sure this is the right way to do it. So that would be my question.. how to have operations per min stats in a C linux console program.

All idea are welcome...

0
Comment
Question by:nfuids
  • 4
  • 3
8 Comments
 
LVL 5

Expert Comment

by:Kocil
ID: 8116094
Gezzz .. the question is a pros,
however this is the third similar topic in short days.
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20543928.html
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20547032.html

Pardon me to wonder if 'asking to experts-exchange' is the top assignment now :)





0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8116400
even if the above links dont help ..
then in short ..
before starting the operations .. set the alarm() ..
then in the SIGALRM signal handler .. do the file ( life) saving stuff .. and then reset the alarm()..
alarm is pretty simple to use .. look at the samples and try on ur own .. and let us know if u r stuck ..

btw  here is short description.. abt the terms i quoted..
alarm() is a function  which sets the timeout for a given amount of time .. after expiration of which .. a signal 'named' SIGALRM  is sent to ur program ...
and in ur program , at the startup, u can set a signal handler . which is executed at once the signal is received .. it doesnt matter what operation ur program was doing .. the moment signal is received .. ur signal handler code is executed ..
and in that signal hander code .. u do up ur saving stuff .. and reset the alarm .. using the alarm() function..

while saving the stuff to the file . make sure you are not saving half-cooked data .. for that sort of checks...u will have to use some global flags .. which indicate that what was the last-status of the 'cooking', before the signal was received..

like at the start of ur processing loop u will have 10 records done and will start the 11th record..

i hope u got the point...
happy coding and good luck
0
 

Author Comment

by:nfuids
ID: 8116740
how do I set the handler function?

Thanks
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:akshayxx
ID: 8116905
if u have function
void signal_handler(){
//do this if SIGALRM comes
}

then to set the signal_handler function .. to be invoked when SIGALRM comes .. do this

signal(SIGALRM, signal_handler);

and to set the alarm
//int time_interval= time in seconds..
alarm(time_interval);

 so after ur call alarm(timeout);
after timeout seconds ur signal_handler will be called ..
0
 
LVL 8

Accepted Solution

by:
akshayxx earned 400 total points
ID: 8116913
u'll need
#include <signal.h>  //for signal constants and signal()

#include <unistd.h> // for alarm()
0
 

Author Comment

by:nfuids
ID: 8117875
Thanks for the tips!!

do you think I should let the file opened during all the software life? or close it between each call ? (let's say the call is being made every minute)

Thanks again
0
 

Author Comment

by:nfuids
ID: 8117885
Also, the alert should be reseted/restarted within the signal_handler function, so the handler is called again in timeout miliseconds, right ?

Thanks
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8118582
it doesnt matter much if u keep the file open ..
it depends who else wud like to access that file ..and in read mode only or some other process can also try to write to it..
but if u plan to keep the file open .. then each time to get to write it .. make sure u call fflush() on it .. so that the whatever u write in the file gets to the disk..

and yes u r right .. in the signal handler function u need to reset the timer.. that takes only singal call
alarm(newtime);
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question