Alternative to Sleep?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternative to Sleep?
# 1  
Old 03-12-2014
Alternative to Sleep?


I've been wondering about this one for some time: Is there an alternative to sleep in bash?

The reason: I'd like to simply limit the amount of processor usage in continuous while : script scenarios without spawning endless sleep processes as well. After beating the manpages, I still haven't a clue as to how one might do something like this...

Any ideas? Is it even possible???

Running 'Buntu 12.04, BTW Smilie

# 2  
Old 03-12-2014
Why is
a problem. You could try using the
subsystem or
# 3  
Old 03-12-2014
Switch to ksh:
$ ksh
$ whence -v sleep
sleep is a shell builtin

Or maybe this...
#! /bin/bash
mkfifo myfifo 2>/dev/null
cat myfifo | while : ; do
        read -t 2 junk
        echo loop $n

This User Gave Thanks to Perderabo For This Post:
# 4  
Old 03-12-2014
As used in the project:-
	read -n1 -s -t$1

Called as delay <time_in_seconds> and has the advantage of keyboard override...
# 5  
Old 03-12-2014
Originally Posted by wisecracker
has the advantage of keyboard override...
However, it requires a tty. Not gonna fly in a cron job or even a background process.
This User Gave Thanks to Perderabo For This Post:
# 6  
Old 03-12-2014
Thanks for the feedback, folks.

However, "read" will not work from an actual script context in Xubuntu 12.04. The "while" simply blows past it; and this comes out every time:

"illegal option -t"


Of course, it'll run just fine directly from the terminal or in any context on Parted Magic...

Anything else to play with out there which has a timeout that might be usable???

Thanks Again!
# 7  
Old 03-12-2014
I guess you have an older bash then. Your only options are to switch to a language with more power or just live with the sleep processes. The sleep processes would not bother me and I don't know why you worry about them.

So ksh, newer bash, or something like perl would all do what you want.

Last edited by Perderabo; 03-13-2014 at 08:29 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sleep while i > 0

Hi, I have a script that runs a process at the beginning and I want to sleep/wait until this process is finished and then continue with the rest of the script. I am trying with this, but it is not working: process=`ps -ef | grep "proc_p01 -c" | grep -v grep | wc -l` if ; do sleep 10 done... (7 Replies)
Discussion started by: apenkov
7 Replies

2. Shell Programming and Scripting

expert , alternative for sleep not use memory

while sleep 1; do pgrep Polo || { kill `pidof Polo` >/dev/null /var/bin/ start & echo `date` R >> /var/log/Check_Polo .log } done exit 0well , i use that script as a watchdog in my box (with has just 32 mb memory) which check every second if... (8 Replies)
Discussion started by: pooyair
8 Replies

3. Solaris

vi alternative

Is there any other editor, installed by 'default' in Sparc Solaris10, besides vi? I'd like to avoid installing anything new. If not, how to make vi more user-friendly? thanks. (8 Replies)
Discussion started by: orange47
8 Replies

4. Shell Programming and Scripting

Alternative for wc -l

Hi techies .. This is my first posting hr .. Am facing a serious performance problem in counting the number of lines in the file. The input files i get will be in some 10 to 15 Gb of size or even sometimes more ..and I will load it to db I have used wc -l to confirm whether the loader... (14 Replies)
Discussion started by: rajesh_2383
14 Replies

5. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

6. UNIX for Advanced & Expert Users

sleep working

unistd.h declares the prototype of the sleep function. where is the sleep function actually defined? where is the control transfered when we include a sleep call in it?? (2 Replies)
Discussion started by: meetbhattu
2 Replies

7. UNIX for Dummies Questions & Answers

Sleep less than 1 second

Does anyone know a way to sleep less than 1 second? Sometimes when I write scripts that iterates a loop many times it would be nice to slow things down, but sometimes 1 second is too much. (9 Replies)
Discussion started by: bjorno
9 Replies

8. Shell Programming and Scripting

Sleep under one second

If I want a script to sleep for less than a second, would I use a decimal? In other words, if I wanted my script to sleep for 1/4 of a second, would I say, SLEEP .25 ?? (5 Replies)
Discussion started by: Scoogie
5 Replies

9. UNIX for Dummies Questions & Answers


what is the purpose of the sleep command? (5 Replies)
Discussion started by: Anna
5 Replies
Login or Register to Ask a Question