Visit Our UNIX and Linux User Community


monitoring running processes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting monitoring running processes
# 1  
Old 12-21-2007
monitoring running processes

I have a script that runs continuously and will deliver a file to multiple servers via scp. On occasions one of the scp's will hang and as a result not complete in sending the remaining files and not loop around again.

If I run the scp commands with a & they'll complete, but I want to make sure the sends have finished before looping again.

My question is how do I monitor the 6 PID's and kill any that have run for more than 2 minutes?

I was going to capture the PID into an array and then use that some how.

Just can't work out the best way.

Any ideas?

They'll be some Christmas cheers for the winner Smilie
# 2  
Old 12-21-2007
post your code
# 3  
Old 12-21-2007
Quote:
Originally Posted by nhatch
I have a script that runs continuously and will deliver a file to multiple servers via scp. On occasions one of the scp's will hang and as a result not complete in sending the remaining files and not loop around again.

If I run the scp commands with a & they'll complete, but I want to make sure the sends have finished before looping again.

My question is how do I monitor the 6 PID's and kill any that have run for more than 2 minutes?

I was going to capture the PID into an array and then use that some how.

Just can't work out the best way.

Any ideas?

They'll be some Christmas cheers for the winner Smilie
Not really after Xmas cheers (not in the mood and will never be Smilie) but here's an idea on how you might monitor and kill any that timed out
Code:
#!/bin/sh

TIMER=120
CMD=scp

mysleep()
{
   sleep $1
   CMDPID=`ps -ef |grep $$ |grep $CMD |grep -v grep |awk '{print $2}'`
   for i in $CMDPID
   do
         kill -9 $CMDPID
   done
}

while true
do
        echo Loop ...
        mysleep $TIMER &
        scp ... ... ...
done

Just put 'mysleep 120 &' before scp'ing, proceed with care, not tested Smilie

Last edited by andryk; 12-21-2007 at 10:09 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #193
Difficulty: Easy
Python was selected the Programming Language of the Year in 2007, 2010, and 2018.
True or False?

9 More Discussions You Might Find Interesting

1. Linux

Running processes

Hi guys is it normal to have 5-10 cron/syslog processes running... in my case i got 10 cron process running. (4 Replies)
Discussion started by: batas
4 Replies

2. Solaris

Running processes on GZ/LZ

Hi guys just a question is it normal to see running process on a non-global zone in the global zone... processes such as cron. (3 Replies)
Discussion started by: batas
3 Replies

3. Shell Programming and Scripting

how to know the running processes.

Hi can anybody help me regarding this.. i want know the output of ps -ef with explanation. how can we know the running processess. this is the output of ps -elf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 19 T root 0 0 0 0 SY ... (1 Reply)
Discussion started by: rajesh_pola
1 Replies

4. UNIX for Advanced & Expert Users

Monitoring cpu usage of mysql processes/threads/queries without any tool

hi all, i want to monitor mysql processes/threads/queries with respect to cpu usage.how can i do it? show processlist is of no use as no information abt cpu usage is given. plz help (7 Replies)
Discussion started by: rohitmahambre
7 Replies

5. Shell Programming and Scripting

Cron job for monitoring processes

I have to monitor several processes in my application . i get the listing of these processes using the command ps -ax i want to write a shell script that will monitor the processes and if a process goes missing then it will send an email to my gmail account. I want to run this... (6 Replies)
Discussion started by: asalman.qazi
6 Replies

6. Programming

Need C program for monitoring a processes that are running in different nodes

Hey, I am doing a high availability project. I need coding(socket programming using C) to monitor processes that are running in different nodes with in a network cluster.At last if u could give me a program in C to monitor the process(whether it is running or failed),it would be very... (2 Replies)
Discussion started by: vigneshinbox
2 Replies

7. UNIX for Dummies Questions & Answers

monitoring 'waiting' processes

Is it possible to monitor processes whether they are waiting or active? Basically I would like to know since which TIME the process has been running and the state. :confused: (3 Replies)
Discussion started by: jon80
3 Replies

8. UNIX for Advanced & Expert Users

Monitoring Processes - Killing hung processes

Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go? Thank you Richard (4 Replies)
Discussion started by: ukndoit
4 Replies

9. Shell Programming and Scripting

Monitoring processes of another host

Does anyone have a script, which monitors the processes of another host? (5 Replies)
Discussion started by: Andimotz80
5 Replies

Featured Tech Videos