?
Solved

alarm ()   and sleep() functions in the same process

Posted on 2003-01-26
6
Medium Priority
?
271 Views
Last Modified: 2012-05-04
Hi All,

I wanted to use alarm() function call in my process
I already have some calls to sleep() function.

I read the man pages for alarm() saying that  
alarm() and sleep() should not be used in the same process. (since sleep() may internally  use SIGALRM)

I wanted to know sugestions from the experts regd. this
problem.

What is the work around/design  if alarm() and sleep()
have to be used in the same process.

Is there any alternative to using alarm() function in the user space.

Thanks for all your help.







0
Comment
Question by:sanjay_thakur
[X]
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
6 Comments
 
LVL 5

Expert Comment

by:bryanh
ID: 7827164
On Linux, sleep() does not use SIGALRM; there is no reason not to use it together with alarm().

On other systems, the way around this is to implement your own sleep by just scheduling an alarm and then waiting (e.g. pause()).  You have to coordinate this with your other use of the alarm signal -- essentially, you need to implement a schedule of events, where at any given time the alarm signal is scheduled to happen when the next event on the schedule is due.
0
 

Expert Comment

by:RenHoek
ID: 7837469
Instead of using sleep() you could in a pinch also use select() to delay your program for a bit. But In my years, I found that I hardly have to use the alarm() function at all, by making sure the program executes a service routine function every now and then, that will check up on everything that needs to be done. :)
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 7927109
Hi RanHoek,

I am not very clear how to use select()

Is this the same select() as with unix sockets.How is that
going to help.

could you please provide a simple example?considering I am
bit new to all this.

Thanks a lot both of you.




0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:bryanh
ID: 7939146
It's the same select.  While its principal purpose is to wait for activity on file descriptors (sockets or other), it also has a timeout parameter.  If you just specify an empty set of file descriptors and specify a timeout, you have the same thing as usleep(), which is the same thing as sleep() but with microsecond precision.

Some people use select() in this abnormal way because it is available on more systems than usleep() and they need more precision than sleep().

Since I mentioned usleep(), I should also mention nanosleep(), which has even more precision than usleep() and has parameters that are sometimes easier to work with.
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 8021718
I would like to split the answer points .

Thanks a lot for all the help.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 75 total points
ID: 8022564
Points reduced for a split.  You can now accept one experts comment as an answer.  After that, make another question in this topic area for the other expert.  Make the question for the amount of points intended.  Label the question, "Question for (Expert Name) and post this question number in the base of the question, i.e. For your assistance in question # --------


Computer101
E-E Admin
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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