Unix programming, multiple timers without sleep() or pause(), etc
Posted on 2003-03-20
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,