UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2015-09-26 12:13 PM

useless79
Member
Registered: 2011-10-10
Posts: 30

time based event generation in C

Hi,

I want to write a C program which generations different events bases on current time slot of the day.
Can any one please let me know which library will be best suitable for this ? eg

infinite_loop  {
       if (2am to 4 am)
              generate event A;
       if (4am to 6 am)
              generate event A;
       if (6am to 8 am)
              generate event A;
...........
...........
}


Thanks

Offline

#2 2015-09-26 02:15 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: time based event generation in C

Well, I'm not sure what exactly you mean by "generate events"...  Are you talking about sending signals or writing to a pipe or calling some callback function or something else?

But, the time-based stuff is easy enough, and doesn't require any library beyond standard libc...  Just use either time() or if you need subsecond precision gettimeofday()...  Then, localtime() to break it down into an easily parsable local time struct so you can easily do the type of time differentiation you seem to be wanting...

Offline

Board footer

Powered by FluxBB