The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-04-2007 11:59 PM
script to run shell command and insert results to existing xml file littlejon Shell Programming and Scripting 5 08-12-2005 01:59 PM
find command not returning any result rraajjiibb UNIX for Advanced & Expert Users 4 07-23-2004 02:05 PM
grep for a process bensky UNIX for Dummies Questions & Answers 3 10-23-2003 01:00 AM
SED Command Returning a Blank File djschmitt UNIX for Dummies Questions & Answers 2 02-27-2003 02:13 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-18-2007
jlitzie's Avatar
Registered User
 

Join Date: Jul 2007
Posts: 4
Question ps | grep command not returning existing process

Hello all,

I develop an ERP application that runs on a number of *nix flavors. This application had been around for quite a number of years.

As part of the application launch, we do a check for a background process using the following command:

ps -ef | grep -v grep | grep mi\/ba | grep databasename | wc -l

This returns the number of processes running (should always be either 1 or 0). If the process is running, it's should be owned by root.

We've used this command for quite a number of years with no problem. Now, for some unknown reason, at one of our customers' sites (AIX 5.1), the command is returning zero even if the process is running. This causes a second background process to start, and usually by a user other than root.

We took the command string and put it into a shell script that just repeated over and over. In 8500 attempts, the command failed about 5 times. That doesn't seem like a lot, but just one causes an extra process to start.

If anyone has a possible as to the cause or how to correct, I would be very appreciative.

Thanks,

JL
Reply With Quote
Forum Sponsor
  #2  
Old 07-19-2007
jgt jgt is offline
Registered User
 

Join Date: Apr 2007
Location: 44.21.48N 80.50.15W
Posts: 348
You could create a lock file, by adding something like the following to the beginning of the background script:
if [ -r lockfile.pid ]
then
echo "Background Process already running "
exit 1
else
echo $$ >lockfile.pid
fi

Then at the end of the background process, and in the system start up process add:
rm lockfile.pid


Then have the foreground application test for the existence of the lock file.

As for why the ps command doesn't always work, is it possible that the pid number disappears from the process list when the process is swapped out.
Reply With Quote
  #3  
Old 07-19-2007
jlitzie's Avatar
Registered User
 

Join Date: Jul 2007
Posts: 4
jgt,

Thanks for the reply.

Using a lock file is one possibility, but I was hoping that I'd be able to resolve the ps issue. Using a lock file could put more burdon on our customers if, for example, the background process dies or is killed but the application is still running. In that case, the user would need to get to the os and delete the file manually. Not all of our customers' are technically adept. Not out of the question, but probably a last resort.

As for your comment:

Quote:
Originally Posted by jgt View Post
As for why the ps command doesn't always work, is it possible that the pid number disappears from the process list when the process is swapped out.
Were you making a statement or asking a rhetorical question

JL
Reply With Quote
  #4  
Old 07-19-2007
kahuna's Avatar
Registered User
 

Join Date: Apr 2007
Posts: 148
I know nothing about AIX. But some man pages on the web for "ps" say, "Programs swapped out to disk will be shown without command line arguments, and unless the c option is given, in brackets."

It's not clear if you are grepping for command line arguments. If you are, and the program is swapped out and the AIX ps is subject to the limitation, it could be failing on the grep for command line arguments.
Reply With Quote
  #5  
Old 07-19-2007
jlitzie's Avatar
Registered User
 

Join Date: Jul 2007
Posts: 4
kahuna,

Yes, the grep is a command line argument. The process itself can be running quite a number of times; it's the main process for the application and each usr who logs in uses the same program.

I guess I'll need to look at alternatives like the lock file. If AIX is swapping out that process, there's not too much I can do. It is curious that we've never, in over 10 years, see this problem. I wonder if the customer in this case changed some parameters that caused AIX to swap out processes more often.

Thanks.

JL
Reply With Quote
  #6  
Old 07-19-2007
kahuna's Avatar
Registered User
 

Join Date: Apr 2007
Posts: 148
OK. You might want to first verify that the AIX ps works this way. I don't know that to be true.
Reply With Quote
  #7  
Old 07-20-2007
jlitzie's Avatar
Registered User
 

Join Date: Jul 2007
Posts: 4
I understand. I don't either

Thanks.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0