You are not logged in.

#1 2006-10-09 05:36:15

Cirdan
Member
Registered: 2006-03-18
Posts: 64

Executing a loop every X amount of seconds

I am thinking about writing a program that gets data from /proc and displays it in the console, maby expand it to a widget or something later. My questions are as follows:

A) How would I get the program to update the information every x seconds, and if I did do that, would it cause problems? Even if I closed the "file" after every loop?

Offline

#2 2006-10-09 10:22:52

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Executing a loop every X amount of seconds

What language? In bash its sleep num, python time.sleep(num), C Sleep(num) (? {or is that from windows.h} [hell I don't know])
Shouldn't cause any problems, just makes your system wait x amount of seconds.

Offline

#3 2006-10-09 10:23:07

torindan2
Member
Registered: 2004-07-15
Posts: 74

Re: Executing a loop every X amount of seconds

I presume you are using C/C++, then there is sleep and usleep I think it's in unistd.h, try man 3 sleep.

But almost in any other language you can find something simmilar.

However the nicest implementation would be to subscribe to notifications from fam, and this way your program will be notified when something changes in /proc filesystem, so you won't be wasting CPU cicles by rescaning every 2 seconds all /proc entries.

Offline

#4 2006-10-10 02:09:28

Cirdan
Member
Registered: 2006-03-18
Posts: 64

Re: Executing a loop every X amount of seconds

Thanks. What I was wonder what would be a problem is scanning /proc for new information every x seconds(I'm thinking 30 seconds might be good enough, maby 25).

And how would I use fam? Also, g++ doesn't seem to know what "string" is. I did include <string> but it says "string needs a type"

EDITED

Offline

#5 2006-10-10 03:47:31

lessthanjake
Member
From: Norway
Registered: 2005-11-09
Posts: 319
Website

Re: Executing a loop every X amount of seconds

#include <strings> and man string will give you all the info you need. To use fam you ned to read the fam documentation.

Offline

Board footer

Powered by FluxBB