Why use select() instead of sleep()?

Language/C 2012. 4. 26. 10:29

출처 :  http://stackoverflow.com/questions/3125645/why-use-select-instead-of-sleep

 

답변 :

Select allow for accurate sub second wait, and is more portable than sleep. There are other ways to wait, see this question.

 

답변 :

Well, sleep(3) may be implemented by using signals. It depends on the platform.

When you use select(2) and poll(2), you know that no signals will be involved, which is often very useful. For example, if you are using alarm(2), you should not use sleep(3) as well, because "mixing calls to alarm and sleep is a bad idea" (according to the man page.)

Also, select and poll give you millisecond granularity when sleeping, but sleep only has a granularity in terms of seconds.


'Language > C' 카테고리의 다른 글

read() 파일 읽기  (0) 2012.05.11
execl 다른 프로그램 실행  (0) 2012.04.26
아스키 코드 0x00 ~ 0x20 까지  (0) 2012.04.10
How to print out thread id from pthread_t  (0) 2012.04.06
Programmiersprache C/C++  (0) 2012.03.16
: