Need help regarding sending sleep to background


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help regarding sending sleep to background
# 1  
Old 01-05-2012
Need help regarding sending sleep to background

Hi,
can we print anything, when sleep is running..?
like printing dots(.. . . . . . . . .) to indicate that some process is going on...?


i mean, can we send sleep to background, proceed with printing, till sleep is going on... in s single step.

I have written a funtion to solve this.
Quote:
function sleep_time() {
C=1
while [[ $C -lt $1 ]];
do
echo -n "."
sleep 0.25
C=$C+1
done
}
sleep_time 100


or directly,
Quote:
#!/usr/bin/ksh
echo "hello here"
(sleep 25)&
pid=$!
while [[ `ps | grep "$pid" | grep -v grep` ]]
do
echo -n ". "
sleep 0.15
done


but cant we do that in a single command, instead of using this much of code.
Help me regarding this.


# 2  
Old 01-05-2012
Quote:
while [[ `ps | grep "$pid" | grep -v grep` ]]
Apart from being a syntax error in ksh, this line can be replaced with the correct command to find out whether you have background processes running (the "jobs" command):
Code:
while [ "`jobs`" ]

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send sleep to background

Hello all, I've a small script where it checks for the existence of a particular file and sleeps for 5 seconds if it doesn't exist. I would like to send the sleep output to background so that I don't see so many sleep messages in the build output. #!/bin/sh -x until do sleep 3 done echo... (17 Replies)
Discussion started by: builderj
17 Replies

2. 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

3. Shell Programming and Scripting

Sending key events to background script

Hi, short summary: I need to send keystrokes from USB keyboard to background (bash-)script. I guess I have to use read on the right devive board but how and which? My details: I got a small home server with some VMs using KVM/Qemu, all are suse 11.3. But in general I work on a client... (0 Replies)
Discussion started by: Snowman
0 Replies

4. 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

5. Shell Programming and Scripting

sending email as background process

Hi All, Solaris Bash v3x I have a script that accepts an error code, and if the error code is not 0 then an email is sent using mailx to details the error. I want to be able to implement the functiuonlity whereby i can send the email in a background process so the script can continue with... (3 Replies)
Discussion started by: satnamx
3 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

sleep

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