Killing a process within 5 min it starts in Unix using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Killing a process within 5 min it starts in Unix using perl
# 1  
Old 01-15-2010
Killing a process within 5 min it starts in Unix using perl

Hi All,

I have to kill a program whose pid, i will be getting.

Multiple processes will be getting started by my script of same kind in a series.

So for after each call to a process i need to write a command or script which can kill the process if it takes more than 5min. In this i will be providing the pid to this command or script.

Is there anyway or command to perform the same? It would be helpful if it is going to be a single command.

This task has to be performed using Perl.

Thanks,
Nishank
# 2  
Old 01-15-2010
if u get the pid already u can use system command of perl to run a system command

system("kill -9 $pid");

Is this is what u r looking for ? How are you calculating the running time of the process ?
# 3  
Old 01-15-2010
Code:
 
watchproc()
{
pid=$!
count=0
while `ps $pid > /dev/null`
do
  if [ $count -gt 300 ]  # 5mins = 300 sec
  then
    echo "killing process $pid"
    kill -9 $pid
  fi
  sleep 1
  count=$(( $count + 1 ))
done
}
tail -f /var/log/messages &
watchproc

# 4  
Old 01-15-2010
Hi Xoops and Ankur,

Thanks for the reply....

Xoops,

it really helps me.

Thanks again,
Nishank
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Unix Script -- To Skip killing a specific process

Hi, By using ps -aux | awk '/mine/{split($15,a,"/");print $1,$2,a}' i get the below listed PID's with there corresponding processes. adm 1522 ABC_Process.tra adm 1939 GENE_Process.tra adm 2729 GENE_Archive.tra adm 3259 xyz_Process.tra I use ps -aux | awk... (5 Replies)
Discussion started by: murali1687
5 Replies

2. UNIX and Linux Applications

Unix pkill error; does wily obstruct me killing the process?

have two scripts on Unix; one that starts some processes and the other one for killing a process. At first, I ran the .sh without WILY in it and it worked perfectly; in this way, I could also ran my stopper process. However I need WILY in this so I added it to my script but this time, a message... (1 Reply)
Discussion started by: nerdogan551
1 Replies

3. Programming

Parent process starts before the child using signal, in C

Hi, i want that the parent process start before the child, this code doesn't work, if the child start before the parent it wait for signal, then the father send the signal SIGALRM and the child catch it and call printf; else the father call printf and send the signal to the child that call its... (1 Reply)
Discussion started by: blob84
1 Replies

4. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

5. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

6. Shell Programming and Scripting

Perl : Kill process within 5 min

From a perl script , How can I monitor a PS which I activated and kill it within 5 minutes in case it didn't complete its tasks.:confused: (2 Replies)
Discussion started by: Alalush
2 Replies

7. Shell Programming and Scripting

Killing of a process and send a mail if the process doesnot come up within 2 minutes

Hi Friends, I am new to this forum as well as new to shell scripting. I have a problem here and i need someone to solve this. Let us consider there are two processes(abc & def).There is a script which kills these two processes(i.e killtheprocess abc). Here abc is the argument . There is a... (1 Reply)
Discussion started by: Prince89
1 Replies

8. Solaris

killing a unix job after the job process gets completed

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. Thanks... (7 Replies)
Discussion started by: dtazv
7 Replies

9. Shell Programming and Scripting

killing unix job after the job process completes

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. ... (1 Reply)
Discussion started by: dtazv
1 Replies

10. Shell Programming and Scripting

Killing a process from perl script.

How do I kill a process, say by name "drec" from a perl script. I tried with : ps -eaf | grep drec | awk '{print $2}' | xargs kill -9. The output I got is : ps -eaf | grep drec | awk '{print }' | xargs kill -9 /usr/bin/kill: ipgen: Arguments must be %job or process ids {But, $2 is not... (3 Replies)
Discussion started by: sharuvman
3 Replies
Login or Register to Ask a Question