Re: triggering an event every 5 minutes in C
From: Pascal Bourguignon (spam_at_mouse-potato.com)
Date: 03/16/05
- Next message: Michael B Allen: "User Defined Macros for UNIX Standards"
- Previous message: James Antill: "Re: Recv on a socket"
- In reply to: Jon Zero: "triggering an event every 5 minutes in C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Mar 2005 04:22:45 +0100
Jon Zero <jzero@nospam.net> writes:
> I am trying to figure out what the best way to have my program do
> something (change the value of a variable) every x number of minutes. Can
> somebody give me a pointer in the right direction? I am writing in C in
> a linux environment.
Read David's answer.
In most cases something like could work, but be sure to read the man
pages of signal(2) and alarm(2):
int variable=0;
int change_variable(int signal){
variable++;
alarm(300); }
int main(){
signal(SIGALRM,change_variable);
alarm(300);
int last=-1;
while(1){
if(last!=variable){
last=variable;
printf("%d\n",variable); }}}
-- __Pascal Bourguignon__ http://www.informatimago.com/ Nobody can fix the economy. Nobody can be trusted with their finger on the button. Nobody's perfect. VOTE FOR NOBODY.
- Next message: Michael B Allen: "User Defined Macros for UNIX Standards"
- Previous message: James Antill: "Re: Recv on a socket"
- In reply to: Jon Zero: "triggering an event every 5 minutes in C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]