How to delay the process for few seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to delay the process for few seconds
# 1  
Old 05-13-2009
Error How to delay the process for few seconds

Hi,

In my shell script, (as per the requirement), I am creating few files, and the processes are launched parallelly . (by using "&" at the end of the command line). As per the logic, I need to remove these files as well, after creating.

But, the problem is, due to parallel processing, (while creation) if i am trying to remove the file, then it is not removing, because the previous process is in progress.

For this problem, I need to introduce some piece of code, (something like wait/sleep), which will give more time to complete these process and step for removing files won't be affected.

Ex-

(grep "pattern1" "file1" "file2" ;echo $? >> thread1.txt) &
(grep "pattern2" "file3" "file4" ;echo $? >> thread2.txt) &

------- Few lines of code ---------
rm -f thread1.txt thread2.txt

Hence, in between set of greps, and remove command, I need to use a piece of code, which will give some more time, to execute the grep to execute successfully. (can I use "sleep 1" over here ? or i need to use something else)

Please give some suggestion as this is very urgent for me. Smilie Thanks for any kind of help.

Thanks and Regards,

Jitendriya Dash.
# 2  
Old 05-13-2009
You can either let the script wait for the background processes, or sleep for a few seconds, or save the PIDs of the background processes ($!) and check ps -ef if they're still running.
# 3  
Old 05-13-2009
You don't you use "predictive sleep" ? I mean, do you know approximately how long does it takes for the last process to finish ? If you give enough time, like 10 seconds or more, for example - sleep 10, would this be enough ? Then, get the status of the last command with $? and proceed based on the answer.
# 4  
Old 05-13-2009
You can test the output from the shell "jobs" command. When there are no background jobs running it outputs nothing.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get how much time process has been running in seconds

I use this command to get the time elapsed for a process ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time | grep perl It gives in format 19990 0.0 0.0 user /usr/bin/php 5-09:58:51 /usr/bin/php I need in seconds. Please use CODE tags for sample input and output as well... (2 Replies)
Discussion started by: anil510
2 Replies

2. UNIX for Dummies Questions & Answers

Delay of upto 7 seconds after typing in putty

Hi Friends, I am facing a very strange issue . I type something on putty session of servers of my work(locating in North America) and it appears only after 7 seconds or so. I am located in India. It doesn't happen with my colleagues who are sitting next to me :(. I use the ssh protocol to connect... (4 Replies)
Discussion started by: kunwar
4 Replies

3. Shell Programming and Scripting

Restart debian server if one specific process has more than 10 seconds have high cpu load

Hi, could someone give me an example for a debian server script? I need to check a process if the process has a high cpu load (top). If yes the whole server needs to reboot. Thats it, nothing more. ;) Hope someone could help me. Regards woisch (2 Replies)
Discussion started by: woisch
2 Replies

4. Shell Programming and Scripting

Convert duration of the process to seconds

Hi, I am looking to write a script to kill the process which are running for more than 7 days. So i have a command like "ps -eo pid,etime,args | grep -i xxxx" ( process which has xxx in it and running for more than 7 days needs to be killed ). When i exeucte the above command , i am... (2 Replies)
Discussion started by: forums123456
2 Replies

5. Red Hat

Fork wait in background process - large delay

hi all, We are trying to run a process in the background and in the process we call fork ;and wait for the child process to finish .We find that the died = wait(&status); happens after 10 seconds randomly and sometimes completes in time (within 1 sec) This behavior is seen only when the... (1 Reply)
Discussion started by: vishnu.priya
1 Replies

6. Red Hat

Fork wait in background process - large delay

hi all, We are trying to run a process in the background and in the process we call fork ;and wait for the child process to finish .We find that the died = wait(&status); happens after 10 seconds randomly and sometimes completes in time (within 1 sec) This behavior is seen only when the... (0 Replies)
Discussion started by: vishnu.priya
0 Replies

7. Programming

how to delay a process from getting killed

We are forking a process B from process A and the process B should display the details it reads from process C(daemon process) continuously. Let us say that the process C sents 100 packets.The process B receives all the 100 packets from the process C before it prints all details of 31... (1 Reply)
Discussion started by: cijkmysj
1 Replies

8. UNIX for Advanced & Expert Users

how to delay a process getting killed before it completes its work

The problem i am encountering is the process is getting killed before it dispalys the details.The details are displayed using printf.I created a new buffer for printing the details using setvbuf function call instead of output buffer.This is not working.The thing is,killing of the process must be... (1 Reply)
Discussion started by: cijkmysj
1 Replies

9. Programming

Delay a process.

How to delay a process. I need to to delay a process from 3sec. At that 3sec other back ground processes also should stop. (just sit 3sec for idle & then starts execution as normally) I use sleep(3)-But it not stop the bg processes I try to use loop but it not gurantee to wait 3sec. ... (2 Replies)
Discussion started by: ugp
2 Replies

10. UNIX for Dummies Questions & Answers

Delay in mv

Working on AIX 4.3 I have an active exe that accepts files for processing on our RS6000. Day to day i store these files in a secure place and at the end of the day I mv them one by one. After some reading and ofcourse trial and error i figured out that this helps... mv `ls -l |head -l | awk... (2 Replies)
Discussion started by: buRst
2 Replies
Login or Register to Ask a Question