Sleep function of Signals

Source: Internet
Author: User
Tags sleep function

# Include <unistd. h> sleep (unsigned

This function suspends the calling process until one of the following conditions is met:

(1) The wall clock time specified by seconds has passed.

(2) Call the process to capture a signal and return it from the signal processing program.

If the alarm signal is the same, because of other system activities, the actual return time is later than the required time.

In the (1) case, the return value is 0. When sleep returns early (Case 2) because a signal is captured, the returned value is the number of seconds (the required time minus the actual sleep time ).

Although sleep can be implemented using the alarm function (http://www.cnblogs.com/nufangrensheng/p/3515013.html), this is not necessary. If alarm is used, the two functions may interact with each other.

Program list 10-21 reliable implementation of sleep

# Include = & newact, & newmask, & = & suspmask, SIGALRM); & suspmask); = alarm (& oldact, NULL );&

 

This blog is excerpted from advanced programming for UNIX environments (version 2) and used only for personal learning records. For more information about this book, see:Http://www.apuebook.com/.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.