Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl "sleep" is not really sleeping

Status
Not open for further replies.

rwalters

MIS
May 31, 2007
5
0
0
US
When I use something like:
$sleeptime = 60;
sleep $sleeptime;

the script still consumes a small amount of system resources while it is supposed to be sleeping. I have tried every variation of the sleep function that I can think of. I have also tried compiling the script, but, it does not change. Anyone have any ideas as to why Perl does not really sleep?
 
I mean.. what is a small amount of system resources? The script still has to be in memory and the process still has to run even while sleeping.
 
how many variations of the sleep function are there?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks for the responses. The resource I am most concerned about is cpu time. This is based on monitoring a perl script and a similarly constructed Korn shell script. The impact of the KSH script on total cpu usage is much less than the impact of the Perl script.

sleep($time);
sleep $time;
`sleep $time`;
system("sleep $time");
 
Well those bottom 2 are going to take up a lot more resources ( I would think) than the top 2.
 
Thanks for the response. I don't understand how you say that. The last two forms effectively pass the command to the OS. How can that use more resources than allowing the Perl interpreter to control the function as the first two would?
 
The last two would consume slightly more resources because...

system() and `` block until the command finishes running. So, not only does the Perl script remain in memory (to continue when the blocking is over), but now there's the `sleep` program running in memory also.

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Yeah.. I guess "a lot more" was kind of a broad statement :)
 
What, if any, effect would the use of:

use POSIX 'sleep';

have on the function of sleep?

Bye the way, in case you can't tell, I am not a Perl heavyweight by any stretch of the imagination.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top