Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Unix programming, multiple timers without sleep() or pause(), etc

Hi,

You have probably seen this question 1,000,000 times already, but I am unable to find any man page or document/post that answers my question.

I have recently made some IRC Services, and everything seems up to scratch. The only thing I cannot figure out is timers. At the moment I have made a _very_ newb substitute by chucking things in a structure and every time it parses information from the IRCd it checks which timers need executing and which expire, etc. Only this causes problems in other areas due to services having to pong the IRCd and sleep() for one second (as data is continuously processed and I didn't want the load average to go through the roof). For some odd reason it creates really weird segmentation faults.

I think I am looking at setitimer() and alarm(), but I can't seem to work out exactly what I need to be doing for my needs. Basically, the services run in the background (forked) and I need a few timers to be set that perform commands, like nick expiries, channel bans, etc. I don't really want to use sleep() or anything because IRCservices shouldn't need sleeping, so I was thinking something along the lines of creating a child process that runs, I think you use the above proc's i mentioned above together with sigalarms, but I'm not really sure. I haven't touched this area of C programming before.

If someone could please point me in the direction of creating timers like this, it would be much appreciated.

Thanks for your time,

Daniel Wallace
0
Longie
Asked:
Longie
1 Solution
 
chris_calabreseCommented:
This is typically done in one of two ways...

1) use select() or poll() on all your read()'s so they timeout and you can go do other stuff for a while
2) use settimer()

Either way you'll probably need to write a little library to handle the multiple timers part (essentially keep a linked list of when the timers are to pop, in order, and what functions to call when they pop)
0
 
liddlerCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by  chris_calabrese

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now