What is the use of sleep() function?

Questions by sripri   answers by sripri

Showing Answers 1 - 9 of 9 Answers

Gopi K

  • Jun 21st, 2007
 

Sleep() suspends execution for an interval

  Was this answer useful?  Yes

The sleep() function will cause the calling thread to be suspended from execution until either the number of real-time seconds specified by the argument seconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. The suspension time may be longer than requested due to the scheduling of other activity by the system. 

Sleep function can be used in the below scenario:


1) Suppose you want to write the unix shell script which will keep on checking the arrival of a file in a particular directory in specified time, say every 10 minutes, so here we can use sleep. The sleep 1000 can be use in the indefinite loop and which will keep on checking the directory where file will arrive (through FTP), and go on sleep after every 10 minutes after checking this directory.

It will save the CPU time.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions