LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-02-2011, 04:09 AM   #1
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Rep: Reputation: 135Reputation: 135
lifetime of a process


Can I catch the lifetime of a process ??

I want to kill a process when its attached to a particular file for 15 minutes.
 
Old 12-02-2011, 06:11 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Not much details about how and what there but sure you can. Depending on your starting point 'fuser' shows which process has the file open when pointed at a file and 'lsof' shows the same but in more detail when given a process Id or directory name.
 
Old 12-02-2011, 06:38 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by unSpawn View Post
Not much details about how and what there but sure you can. Depending on your starting point 'fuser' shows which process has the file open when pointed at a file and 'lsof' shows the same but in more detail when given a process Id or directory name.

Actually I have a list of numbers in a file ...

By rsh I am executing one exe remotely in windows on the numbers in the list ...

I want to kill the rsh when the exe is associated with a number for more than 15 minute ...

Eachtime the rsh calls the exe and run it from the list of numbers one by one but if there is error then the exe hangs permanently ..

I am automating a this thing ..

so if there is error/rsh(exe) is associated with one number for more time then it'll be killed.
 
Old 12-02-2011, 07:29 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Apart from it being better to fix the cause of the error than to focus on the symptoms, the problem may be you need a clear indication the process hangs. If stdout / stderr show any then you could redirect that to a temporary file, regularly grep it for specific error messages and kill based on the outcome of that. OTOH if remote resources and processing concurrency aren't the issue then you could try a different approach and run several processes simultaneously (Schedule service, AT service or "Task scheduler") and then kill the remaining processes after a period of time...
 
1 members found this post helpful.
Old 12-02-2011, 10:42 PM   #5
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by unSpawn View Post
Apart from it being better to fix the cause of the error than to focus on the symptoms, the problem may be you need a clear indication the process hangs. If stdout / stderr show any then you could redirect that to a temporary file, regularly grep it for specific error messages and kill based on the outcome of that. OTOH if remote resources and processing concurrency aren't the issue then you could try a different approach and run several processes simultaneously (Schedule service, AT service or "Task scheduler") and then kill the remaining processes after a period of time...
No actually , while rsh is calling the exe on remote machine it generates no error but only hanged .

The only error exist in the file whose numbers are listed in the txt file.

So if the process is hanged then its sure that the error is in the number means in the file because the file may be corrupted ( the numbers are extracted from files )which is in the list and needs to be extracted .
 
Old 12-04-2011, 09:02 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Quote:
Originally Posted by divyashree View Post
So if the process is hanged then its sure that the error is in the number means in the file because the file may be corrupted ( the numbers are extracted from files )which is in the list and needs to be extracted .
...so it makes sense to check the file for errors before submitting, right?


Quote:
Originally Posted by divyashree View Post
No actually , while rsh is calling the exe on remote machine it generates no error but only hanged .
No idea what you're processing (lack of details) and how but can this "exe" generate verbose and or error output you could parse?
 
Old 12-05-2011, 01:36 AM   #7
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by unSpawn View Post
...so it makes sense to check the file for errors before submitting, right?



No idea what you're processing (lack of details) and how but can this "exe" generate verbose and or error output you could parse?
Yes.

PHP Code:
rsh ${WinServer} -"c:\\BatchScript\\Scripts\\APP.exe $cnumber
The above line is in the script and when executes, a line like this appears in process list:

PHP Code:
rsh 172.25.121.75  -"c:\\BatchScript\\Scripts\\APP.exe 3990121212" 
And from this I will catch the last number, normaly if the file(number) is ok, it finished in 2-3 minutes , then killed and process a new number .

But if the the file(number) is corrupted then then it is killed manually to process the next number.

I have to automatically kill the process if it is associated with a same number for more than 15 minutes and I'll extract the number from this line.

Last edited by divyashree; 12-05-2011 at 04:19 AM.
 
Old 12-07-2011, 06:18 AM   #8
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,362

Original Poster
Rep: Reputation: 135Reputation: 135
I got a way to achieve this.

PHP Code:
#!/bin/sh

#set -x



#ps -ef | grep -i rsh | awk '{ print $2 " " $5 " " $12 }' | while read psinfo;
ps -ef grep -i rsh | while read psinfo;
do

PNBR=`echo $psinfo | grep -i exe |  awk '{print $12}'`
PSID=`echo $psinfo | grep -i exe | awk '{print $2}'`
ST=`echo $psinfo | grep -i exe | awk '{print $5}' | awk -F : '{print $2}'`
EN=`ps -ef | grep -i rsh | grep -v exe | awk '{print $5}' | awk -F : '{print $2}'`


echo 
"The number is $PNBR"
echo "The pid is $PSID"
echo "The start minute of the process is $ST"
echo "Current minute is $EN"




function timecalc () {

export MAX=15

if [ $EN -gt $ST ];then
     DIFF
=`expr $EN - $ST`
     else
        
EN=`expr $EN + 60`
        
DIFF=`expr $EN - $ST`

# echo $DIFF
fi

echo $DIFF

if [ $DIFF -ge $MAX ];
 
then
   
echo "Killing the hanged process with PID $PSID running from last $DIFF minutes"
  
#kill -9 $PSID
fi



 
}

timecalc
done 
Because I was getting these 2 line while doing ps -ef | grep -i rsh
Code:
omfprod   3550 21799  0 16:40 pts/4    00:00:00 grep -i rsh
omfprod  22168 22128  0 13:45 ?        00:00:00 rsh 172.25.121.75 -n c:\BatchScript\Scripts\APP.exe 3990180050013
where the line with no exe is created at current time.


Any suggestion will be welcome.

I wrote it but dont know at which time call this.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MAC table lifetime brgsousa Linux - Software 3 09-23-2010 07:18 PM
smartmontools gives a 0 lifetime. What does it mean? konqi Linux - Hardware 5 08-22-2009 11:42 AM
Wacom Volito2 lifetime? MasterOfTheWind Linux - Hardware 1 06-19-2006 06:37 AM
Lifetime membership Dirty_Ink Linspire/Freespire 7 05-13-2004 12:41 AM
LIFETIME Shell MDurai General 1 04-01-2002 04:56 AM


All times are GMT -5. The time now is 08:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration