Alternative to Sleep?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternative to Sleep?
# 8  
Old 03-13-2014
Bit of lateral thinking here.
How about using the sound card as your delay; ensure it is enabled at maximum volume.
Some demo code to show as an example, OSX 10.7.5 default bash terminal, just
comment out the "afplay" lines and uncomment the "aplay" lines for Ubuntu:-
#!/bin/bash --posix
# timer
# *********************************************************
# Generate a 1 second delay and beep.
# Issued as Public Domain, CC0. You may do with it as you please.
# *********************************************************
if [ ! -e "/tmp/sinewave.wav" ]
	> /tmp/sinewave.wav
	printf "\x52\x49\x46\x46\x64\x1F\x00\x00\x57\x41\x56\x45\x66\x6D\x74\x20\x10\x00\x00\x00\x01\x00\x01\x00\x40\x1F\x00\x00\x40\x1F\x00\x00\x01\x00\x08\x00\x64\x61\x74\x61\x40\x1F\x00\x00" >> /tmp/sinewave.wav
	cp /tmp/sinewave.wav /tmp/timer.wav
	for n in {0..999}
		printf "\x80\x26\x00\x26\x7F\xD9\xFF\xD9" >> /tmp/sinewave.wav
		printf "\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F" >> /tmp/timer.wav
# *********************************************************
# The line below uses various Linux flavours, "aplay"...
# aplay /tmp/sinewave.wav
# *********************************************************
# Use the OSX default basic command line audio player, "/usr/bin/afplay".
afplay /tmp/sinewave.wav
# aplay /tmp/sinewave.wav
# A demo delay of around 6 seconds, about 1.5 seconds per loop.
for n in {1..4}
	# aplay /tmp/timer.wav
	afplay /tmp/timer.wav
afplay /tmp/sinewave.wav
# aplay /tmp/sinewave.wav
# *********************************************************
exit 0
# Enjoy finding simple solutions to often very difficult problems...

Last login: Thu Mar 13 08:19:23 on ttys000
AMIGA:barrywalker~> chmod 755 timer
AMIGA:barrywalker~> ./timer
AMIGA:barrywalker~> ./timer &
[1] 247
AMIGA:barrywalker~> _

You have the added advantage of having a 1 second pure sinewave burst too!
This User Gave Thanks to wisecracker For This Post:
# 9  
Old 03-13-2014
Well, it does save a sleep process, I guess. But I think he wants to avoid any new processes.
# 10  
Old 03-13-2014
Hi Perderabo...

Well it __might__ be useful to systems that do not have the "sleep" command.
Android for example.

As it is a wave file the principle could be used to create a function generator
system on just about any platform and use the default player on said platform
as the signal source.

Already working on my BlackBerry 'phone ready for calibrating the AudioScope...

This snippet was just a side effect that could be useful...
# 11  
Old 03-13-2014
Thanks, wisecracker, for those keen insights. It'll take me a bit to unravel & apply, but I know I learned something useful here Smilie

Bit of lateral thinking here
Found the solution to the "read -t" issue in my bumblings about.

This works Smilie:

while :
    echo pausing...
    read -t 2

Indeed, Ubuntu loves a certain incarnation of dash; which, for some reason, is averse to "read." Nasty habit, that /bin/sh bangline...

(FWIW, I was given to understand bash would automagically "step in" when situations such as this came up (as is done in Parted Magic), hence the default /sh bang usage...)

At any rate, and if folks could humor me a moment longer, how might we go about forming a commandline to point read at empty space (via -u, perhaps?) as opposed to taking user input? Possible???

Thanks again --

Last edited by LinQ; 03-13-2014 at 11:29 AM.. Reason: Grammar...
# 12  
Old 03-13-2014
Perhaps this will do what you want:read -t3 A </dev/zero
This User Gave Thanks to RudiC For This Post:
# 13  
Old 03-13-2014
Originally Posted by LinQ
Indeed, Ubuntu loves a certain incarnation of dash; which, for some reason, is averse to "read."
Not so much "averse to read" as "averse to nonstandard bash features".

Nasty habit, that /bin/sh bangline...
Yes, if using nonstandard bash features, one should really warn people in the hashbang.
This User Gave Thanks to Corona688 For This Post:
# 14  
Old 03-13-2014

Sure thing. What's even more confusing is how certain distros handle the situation with an /sh bangline; some gracefully, some not...


Awesome! Looks like a good way of working around the need to invoke a new process just to "sleep" in bash Smilie

FWIW, this was the best I could cobble together today:
read -t 3 -s -N 1000000 nop

(UPDATE- Tested here and there: Dairy-free! Smilie)

If you have a moment, could you give a quick thumbnail sketch to unpack what's going on in your snippet?

Thanks, all!

---------- Post updated at 11:40 AM ---------- Previous update was at 11:33 AM ----------


Caught a bug!

If one holds the return key, your commandline halts everything with this error:
xrealloc: ../../bash/builtins/../../bash/builtins/read.def:525: cannot allocate 134217840 bytes (536911872 bytes allocated)

Code context:

while :
    echo pausing...
    read -t3 A </dev/zero


Last edited by LinQ; 03-16-2014 at 11:12 AM.. Reason: Update . . .
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