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

Posted on 2003-03-20
Medium Priority
Last Modified: 2013-12-26

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
Question by:Longie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Accepted Solution

chris_calabrese earned 150 total points
ID: 8181161
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)
LVL 18

Expert Comment

ID: 9845961
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.


EE Cleanup Volunteer

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question