Go to http://examples.oreilly.com/upt3 for more information on: sleep
The sleep command waits. That's all it does. (GNU versions are usually loaded with features, but the sleep on the CD-ROM [see http://examples.oreilly.com/upt3] doesn't do more than the standard version.) So what good is it?
A quick-and-dirty reminder service when you don't have leave. This will print the message Time to go now.... in 10 minutes (600 seconds):
( ) & Section 43.7, ; Section 28.16
% (sleep 600; echo Time to go now....) &
You can't use at (Section 25.5), and you have to run a job later (say, in three hours):
% (sleep 10800; someprog) &
To watch a program (usually a shell script) that's running in the background and see what processes it runs:
!! Section 30.8
% prog & [1] 12345 % sleep 5;ps PID TT STAT TIME COMMAND 18305 p4 S 0:01 -csh (csh) 18435 p4 S 0:00 /bin/sh prog 18437 p4 D 0:00 /bin/sort -r temp 18438 p4 R 0:00 ps % !!;!!;!!;!!;!! sleep 5; ps; sleep 5; ps; sleep 5; ps; sleep 5; ps; sleep 5; ps PID TT STAT TIME COMMAND ... ...5 seconds pass... PID TT STAT TIME COMMAND ...
When you're running a series of commands that could swamp the computer, to give it time to catch up. For instance, the mail (Section 1.21) program starts background processes to deliver the mail. If you're sending a bunch of form letters, sleep five or ten seconds after each one:
foreach Section 28.9
% foreach name (`cat people`) ? formltrprog $name | mail $name ? sleep 10 ? end
Or, to send print jobs while you're at lunch -- but give other people a chance to print between yours:
% lp bigfile1;sleep 600;lp bigfile2;sleep 600;lp bigfile3
Copyright © 2003 O'Reilly & Associates. All rights reserved.