Re: Sleep
Hi, I might be being a noob but reading the OP, aren't they wanting to call the value arbitrarily? Meaning, e.g. an Ajax call in a web page could send a request to find out the time remaining in the sleep. I guess that the sleep (which will halt the script) needs to be invoked after forking a decrementing counter? The decrementing counter will run asynchronously and could be queried using Fork::Super bg_eval, but if you are asking this question that might be a stretch (it's not something I've used). As there is 'always more than one way to do it' I would use a fork and a file: The simplest method, if it will do what you want would be to use an until loop to count down and do the sleeping, but you would need to decide up front whether you want to return a value (you could always write it to a file and call the contents of the file?). Need more info on what you want to do with it, but on a basic level, this will work. It passes the sleep time value to countdown and forks that process so the rest of the script can proceed. I put the actual 300 sec sleep at the bottom, but if you cat countdown.txt at any point it will tell you how long is left. #!/usr/bin/perl -w use strict; my $sleep_timer; my $count_amount=('10'); if ( ! fork() ) { countdown($count_amount); } Fork the counting process sub countdown { $sleep_timer = shift; print_remaining($sleep_timer); ##I've put the printing in a routine ## as we need it in two places sleep 1; ### Do the first second sleep before decrementing the counter ### That way it will get all the way down to zero until ($sleep_timer == '0') { $sleep_timer--; print_remaining($sleep_timer);###Pass the current count to our printing sub sleep 1; } } sub print_remaining { my $counter = shift; open FH1 ,+countdown.txt; print FH1 $sleep_timer; close FH1; } ### The main part of the script will hold on until the time has sleep 10; print I waited $count_amount seconds to tell you this; BEWARE using forks that you have some failsafe in place to stop the script being run multiple times, or the same sub will overwrite the counter file so the number will start to jump around all over the place. Hope thats useful. Ed On 16 Sep 2013, at 00:49, John W. Krahn jwkr...@shaw.ca wrote: Shawn H Corey wrote: On Sun, 15 Sep 2013 13:00:36 -0700 Unknown Userknowsuperunkn...@gmail.com wrote: If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks, Not directly. You have to record the time before the sleep and then you can measure how long the sleep lasted. my $started_sleep = time; sleep 300; my $time_asleep = time - $started_sleep; Or just: my $time_asleep = sleep 300; John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sleep
(DOH - Obviously I was using 10 seconds to test!) On 16 Sep 2013, at 00:49, John W. Krahn jwkr...@shaw.ca wrote: Shawn H Corey wrote: On Sun, 15 Sep 2013 13:00:36 -0700 Unknown Userknowsuperunkn...@gmail.com wrote: If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks, Not directly. You have to record the time before the sleep and then you can measure how long the sleep lasted. my $started_sleep = time; sleep 300; my $time_asleep = time - $started_sleep; Or just: my $time_asleep = sleep 300; John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sleep
On Sun, Sep 15, 2013 at 6:59 PM, Charles DeRykus dery...@gmail.com wrote: left: , $start+$sleep -time() }; ... Actually, this is wrong because if sleep(3) is interrupted by any signal it will return, so something like this should work, eg my $secs_to_sleep = 60; my $start = time(); my $end = $start + $secs_to_sleep; my $slept; do { local $SIG{USR1} = sub{ say time left: , $end - time()}; my $slept = sleep($secs_to_sleep); $secs_to_sleep -= $slept; } while ( $secs_to_sleep 0 ); -- Charles DeRykus
Re: Sleep
On Sun, 15 Sep 2013 13:00:36 -0700 Unknown User knowsuperunkn...@gmail.com wrote: If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks, Not directly. You have to record the time before the sleep and then you can measure how long the sleep lasted. my $started_sleep = time; sleep 300; my $time_asleep = time - $started_sleep; -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sleep
Shawn H Corey wrote: On Sun, 15 Sep 2013 13:00:36 -0700 Unknown Userknowsuperunkn...@gmail.com wrote: If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks, Not directly. You have to record the time before the sleep and then you can measure how long the sleep lasted. my $started_sleep = time; sleep 300; my $time_asleep = time - $started_sleep; Or just: my $time_asleep = sleep 300; John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sleep exactly after n seconds (sleep finishing longer than specified)
On Wed, Apr 22, 2009 at 09:27, Michael Alipio daem0n...@yahoo.com wrote: Hi, I have a script that forks a child. at the parent, i have a line that tells it to sleep for n seconds. Once the 3 seconds have passed, it will kill the child process. I noticed that most of the time, sleep doesn't count exact seconds.. most of the time it's longer. Is there any way to sleep precisely for n seconds? snip Not unless you are using a realtime OS. Your process might not get CPU time for n+m seconds. Until your process gets CPU time it doesn't matter what you put in sleep, nothing will happen. You may be able to schedule a process such that it will always have CPU time, but performance will suffer for everything else (which is why realtime OSes suck for everything but medical, weapon systems, and other tasks that must have sub-microsecond timing). You must trade speed for precision. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sleep exactly after n seconds (sleep finishing longer than specified)
Michael Alipio wrote: Hi, Hello, I have a script that forks a child. at the parent, i have a line that tells it to sleep for n seconds. Once the 3 seconds have passed, it will kill the child process. I noticed that most of the time, sleep doesn't count exact seconds.. most of the time it's longer. Is there any way to sleep precisely for n seconds? Not really, but you can get finer grained timing using select() perldoc -f select Or the Time::HiRes module. perldoc Time::HiRes John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Sleep
Hi, How could I introduce a Sleep in Perl? Is there any specific function for that? regards, -ramesh Yes. It's called sleep sleep n - will sleep for n seconds (miss off the number and it'll sleep until interrupted) Capgemini is a trading name used by the Capgemini Group of companies which includes Capgemini UK plc, a company registered in England and Wales (number 943935) whose registered office is at No. 1 Forge End, Woking, Surrey, GU21 6DB. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Sleep
Thank You. -Original Message- From: Taylor, Andrew (ASPIRE) [mailto:andrew.tayl...@hmrcaspire.com] Sent: Wednesday, March 04, 2009 3:51 PM To: beginners@perl.org Subject: RE: Sleep Hi, How could I introduce a Sleep in Perl? Is there any specific function for that? regards, -ramesh Yes. It's called sleep sleep n - will sleep for n seconds (miss off the number and it'll sleep until interrupted) Capgemini is a trading name used by the Capgemini Group of companies which includes Capgemini UK plc, a company registered in England and Wales (number 943935) whose registered office is at No. 1 Forge End, Woking, Surrey, GU21 6DB. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sleep apnea
On Oct 16, 2:09 pm, [EMAIL PROTECTED] (Jenda Krynicky) wrote: use FileHandle; The FileHandle module exists largely for reasons of backward compatibility. New code should: use IO::Handle; or use IO::File; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Sleep apnea
Try setting buffering off, its probably due to that as it should do a,b,c -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 16 October 2007 02:50 To: beginners@perl.org Subject: Sleep apnea I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? BTW, I did perldoc -f sleep. If it explains this behavior, I didn't understand it. Kevin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ This e-mail is from the PA Group. For more information, see www.thepagroup.com. This e-mail may contain confidential information. Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments. If you have received it in error, please contact the sender immediately. Any opinion expressed in this e-mail is personal to the sender and may not reflect the opinion of the PA Group. Any e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business practices. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Sleep apnea
On 10/15/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? BTW, I did perldoc -f sleep. If it explains this behavior, I didn't understand it. snip You didn't find anything in perldoc -f sleep because the problem is not with sleep. The pause is there, but STDOUT is buffered by default so you will not see the result of the first print until the buffer is full, you print a \n, or the program exits. Try this instead: use strict; use warnings; print 8*8, \n; sleep 3; print 7*7, \n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Sleep apnea
On Oct 16, 6:11 am, [EMAIL PROTECTED] (Chas. Owens) wrote: On 10/15/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? BTW, I did perldoc -f sleep. If it explains this behavior, I didn't understand it. snip You didn't find anything in perldoc -f sleep because the problem is not with sleep. The pause is there, but STDOUT is buffered by default so you will not see the result of the first print until the buffer is full, you print a \n, or the program exits. Try this instead: use strict; use warnings; print 8*8, \n; sleep 3; print 7*7, \n; Rather than changing the output by adding newlines, you can simply turn output buffering off: $|++; Read about the $| variable in `perldoc perlvar` Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Sleep apnea
From: [EMAIL PROTECTED] I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? Standard output is line-buffered by default. Try: use strict; use warnings; use FileHandle; STDOUT-autoflush(); print 8*8; sleep 3; print 7*7; HTH, Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: sleep under windows cmd
$| = 1; #Autoflush print First; sleep 2; print Second; -Will --- Handy Yet Cryptic Code. Just to Look Cool to Look at and try to decipher without running it. Windows perl -e printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e Unix perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'
Re: sleep under windows cmd
On 02/22/04 05:09, daniel wrote: Hi helpers, I'm very new in perl programming(in programming at all acutally) and wondering about the following piece of code which I was running under W2K command-line: print First; sleep 2; print Second; I thought the script would print First then wait for 2 seconds and than print Second. But the script ist waiting 2 seconds first and than it print FirstSecond By default, output to the console is buffered for efficiency. Since output to the console is relatively expensive in terms of time the system libraries will save up a couple of output operations and ouput it at once. Most of the time this is what you want, but occasionally it gets in the way. The perl idiom for turning of the output buffering to the console is: $| = 1; (You can look up the special variable $| in the perlvar manpage.) Put the above line at the top of your script and output will be unbuffered, i.e. it will appear as soon as the print function is completed. Regards, Randy. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sleep does not work when SIGIO is handled (O_ASYNC). why?
On Dec 28, 2003, at 2:57 AM, Artem Koutchine wrote: [..] In order not to waste CPU time and have server do something usufull (like calculating something) i tried handling SIGIO, so, when data is available on incoming connection i handle and when there is no data, server does its own job. However, it figures, that when i added fcntl(STDIN, F_SETFL, O_ASYNC|O_NONBLOCK); sleep(5) stopped working right. It does not wait for 5 seconds any longer, but actually for about 1/3 second and fully ignores the sleep time a specify (you can run the server and connect to it using telnet and see for yourself). I could not find any info on sleep (SIGALRM) messing with SIGIO and O_ASYNC mode. Any ideas what's going on and how to fix this? [..] this sounds like one of the 'bugs' in perl 5.8.0 and/or 5.8.1 that is suppose to be fixed in 5.8.2 - One strategy would be to create a SIGALRM handler that would set a flag value you could check to see if your alarm went off and was handled. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: sleep question
-Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 12, 2002 12:37 PM To: [EMAIL PROTECTED] Subject: sleep question Greetings, I have a script that forks 5 children. I print to screen when each child gets forked. Under certain conditions in the script a child should sleep. This conditions occurs at different times for each child. I think I am noticing that when the sleep is called in a child, every child and the parent sleep as well. Am I correct in this assumption? No. After the fork, parent and child lead separate lives. Something else is going on. The OS that the script is running on is Solaris. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sleep
On Fri, 22 Jun 2001, Jerry Preston wrote: I have a perl cgi script that works great. I want to put it into and endless loop, put my problem is that my page keeps adding onto it's self. How do I redisplay the web screen without it adding on to it? How are you doing this? You probably want the script to redirect to itself. Can you post some code? -- Brett http://www.chapelperilous.net/btfwk/ Soap and education are not as sudden as a massacre, but they are more deadly in the long run. -- Mark Twain
Re: sleep () and print ()
I am apparently missing something. Being aware of buffering, I suspect. Various parts of the 'pipe' between your print statements and the final destination do some sort of buffering. You can switch some of this off in perl by specifying: $| = 1;
Re: sleep () and print ()
Thank you. worked like a charm. On Saturday 16 June 2001 12:52, Me wrote: I am apparently missing something. Being aware of buffering, I suspect. Various parts of the 'pipe' between your print statements and the final destination do some sort of buffering. You can switch some of this off in perl by specifying: $| = 1; -- Jim Gallott West Meadows Farm, New Haven VT [EMAIL PROTECTED] http://www.westmeadowsfarm.com