Which is more efficient - sleep or infinite while?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Which is more efficient - sleep or infinite while?
# 1  
Old 08-20-2008
Which is more efficient - sleep or infinite while?

Hi
i need to make a script to check disk space every hour.

****Note that cron is not allowed.

So i need to use either sleep or while 1 ...pls suggest which is more efficient in this scenario?

And is there any other way to do the task?

Thanks,
Ashish
# 2  
Old 08-20-2008
The most efficient and simple way is while and sleep.

Code:
while [ 1 ]
do
    your_stuff...
    sleep 3600
done

# 3  
Old 08-20-2008
Quote:
Originally Posted by redoubtable
The most efficient and simple way is while and sleep.

Code:
while [ 1 ]
do
    your_stuff...
    sleep 3600
done

Hi thanks for reply ..
if i use sleep with goto ..will that be moe effiecient as comapred to while 1?

Also what are drawbacks of sleep and while 1.
# 4  
Old 08-20-2008
I would say that's pretty much the same thing (while and goto) but for the sake of simplicity I would advise you go use while.

There are no drawbacks in sleep and while 1. It does it's job and then simply does nothing for 3600 seconds.
# 5  
Old 08-21-2008
actaully, as i have recently learned, [ 1 ] is not the best way

Code:
while :
do
     some stuff
     sleep 11101
done

# 6  
Old 08-21-2008
Quote:
Originally Posted by broli
actaully, as i have recently learned, [ 1 ] is not the best way

Code:
while :
do
     some stuff
     sleep 11101
done

I always use
while : ; do
myself and I would never use
while [ 1 ] ; do
but I wonder why you object to it. I object to it because it is a terribly misleading construct:
Code:
$ [ 1 ] && echo yes
yes
$ [ 0 ] && echo yes
yes
$ [ xyzzy ] && echo yes
yes
$

Few people expect all 3 of those to behave the same. But assuming that : and [ are both shell built-in commands, they should be about as fast.
# 7  
Old 08-21-2008
you wanna know the draw back of sleep??
try running
timex sleep 60
it will give any idea..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Infinite loop query

I have a script script.shwhich is scheduled to run at 11 AM everyday. # script.sh Code: ./scb_script.sh & unfortunately scb_script.sh is running today in infinite loop as respective files are not available. My question, when script.sh starts running tomorrow, will the old process be... (1 Reply)
Discussion started by: JSKOBS
1 Replies

2. Homework & Coursework Questions

Help with infinite loop problem

1. The problem statement, all variables and given/known data: My problem is an infinite loop when i press any other key other then Y or y in the while loop. what i want it to do is return to the normal script outside of it if pressing N or n or keep asking the same question if its any other... (4 Replies)
Discussion started by: Ren_kun
4 Replies

3. Programming

Infinite thread

I created a thread which pings a machine for every 15 seconds. I made my thread function in infinite loop. Main process also in infinite loop and will run for years. I wonder the thread will continue as long as main process continuous or will thread terminates at some point? Is there any life... (6 Replies)
Discussion started by: satish@123
6 Replies

4. Shell Programming and Scripting

Infinite while loop

what is the difference between while:,while true and while false? (6 Replies)
Discussion started by: proactiveaditya
6 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. Shell Programming and Scripting

infinite while do loop problem

hi all, this is how my scrip looks like #!/bin/sh bindir='/opt/apps/script/bin' datadir='/opt/apps/script/data' dir='/opt/apps/script' while : ; do ls -1rt /opt/apps/script/data/check.txt*|tail -1 > /dev/null 2>&1 if ;then chmod +rwx $bindir/dummy2.sh ... (8 Replies)
Discussion started by: tententen
8 Replies

7. Shell Programming and Scripting

Infinite loop not looping

Hi guys, I'm having a problem getting my infinite loop to loop. It simply reads in the users choice form the menu, executes the corresponding case statement and quits instead of looping back to the main menu again. I have a feeling it might be something with my if then statements within the case... (2 Replies)
Discussion started by: hootdocta5
2 Replies

8. UNIX for Advanced & Expert Users

handling Infinite fork

how Unix handles as process which forks infinitely. like ....... while(1) fork(); ........ What happens when it is executed and how to avoid it. Thanks, Ashish (3 Replies)
Discussion started by: ashish_uiit
3 Replies

9. Solaris

ls command in infinite Loop

Hi, whenever I am giving a 'ls' command system is going into infinite loop displaying the current home directory. There is no separate shell script/file with ls name anywhere in the system. I am using Solaris 10. Any help / guidance in solving this problem is highly appreciated. ... (3 Replies)
Discussion started by: umakant
3 Replies
Login or Register to Ask a Question