how to start a process and make it sleep for 5 mins and then kill that process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to start a process and make it sleep for 5 mins and then kill that process
# 1  
Old 03-27-2007
how to start a process and make it sleep for 5 mins and then kill that process

how to start a process and make it sleep for 5 mins and then kill that process
# 2  
Old 03-27-2007
write a script and give sleep function in that.call it with background process by running
Code:
scriptname &

# 3  
Old 03-27-2007
I need a script like this

while [ 0 -le 5 ] #which is infinite while loop
do
./my_function_which_prints_hi_every_5secs #written in C & stored
sleep 10
killall -9 ./my_function_which_prints_hi_every_5secs #shuld kill program
done

Last edited by shrao; 03-27-2007 at 09:36 AM..
# 4  
Old 03-27-2007
Code:
scriptname &; sleep 300; kill $!

# 5  
Old 03-27-2007
I am getting error no process killed for the command kill$!

I tried this method,still I am getting no process killed. can you justhelp in this
I=1
while [ $I -le 2 ]
do
scriptname &
sleep 10
killall -9 scriptname
echo $I
I=`expr $I + 1`
done
# 6  
Old 03-27-2007
Code:
do_something &
sleep 300
kill $!

# 7  
Old 03-27-2007
Quote:
Originally Posted by shrao
I tried this method,still I am getting no process killed. can you justhelp in this
I=1
while [ $I -le 2 ]
do
scriptname &
sleep 10
killall -9 scriptname
echo $I
I=`expr $I + 1`
done
you havent used kill $! to kill the last background process
use that !

instead of
Quote:
killall -9 scriptname
use
Code:
kill $!

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

2. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

3. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (1 Reply)
Discussion started by: naveeng
1 Replies

4. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

5. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

6. Shell Programming and Scripting

grep the process id and kill all the filtered process

Hi I want to write a shell script which can find the process id's of all the process and kill them eg: ps ax | grep rv_ 3015 ? S 0:00 /home/vivek/Desktop/rv_server 3020 ? S 0:00 /home/vivek/Desktop/rv_gps 3022 ? S 0:00 /home/vivek/Desktop/rv_show ... (7 Replies)
Discussion started by: vivek_naragund
7 Replies

7. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

8. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

9. Shell Programming and Scripting

Script - How to automatically start another process when the previous process ends?

Hi all, I'm doing automation task for my team and I just started to learn unix scripting so please shed some light on how to do this: 1) I have 2 sets of datafiles - datafile A and B. These datafiles must be loaded subsequently and cannot be loaded concurrently. 2) So I loaded datafile A... (10 Replies)
Discussion started by: luna_soleil
10 Replies

10. UNIX for Advanced & Expert Users

my process is going to sleep mode after 12 hours but i need my process in in firsy pr

hi all I process is sleeping after 12 hours but i need to be run this to 24 hours but it goes in sleep mode after 12 hours what should i do to make process always running.Kindly give me suggestion. (0 Replies)
Discussion started by: mukesh_rakesh1
0 Replies
Login or Register to Ask a Question