ps | grep command not returning existing process


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users ps | grep command not returning existing process
# 1  
Old 07-18-2007
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
# 2  
Old 07-19-2007
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.
# 3  
Old 07-19-2007
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
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 questionSmilie

JL
# 4  
Old 07-19-2007
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.
# 5  
Old 07-19-2007
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
# 6  
Old 07-19-2007
OK. You might want to first verify that the AIX ps works this way. I don't know that to be true.
# 7  
Old 07-20-2007
I understand. I don't eitherSmilie

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Process to add mount point in Sun Cluster existing HAplus resource

Hi Well I would like to know step by step process of adding a mountpoint in HAPLUS resource in SUN cluster as I go the below command to add a mount point but not the step by step process of adding a mount point in existing HA Plus resource. clrs set -p FileSystemMountPoints+=<new_MP>... (3 Replies)
Discussion started by: amity
3 Replies

2. Red Hat

RHEL6 : Remote process exited without returning status

Hi All, I am using RHEL 6 linux in my lab server and I am new to RHEL6 features. lab1:root> uname -a Linux lab1 2.6.32-358.18.1.el6.x86_64 #1 SMP Fri Aug 2 17:04:38 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux I am facing a peculiar issue in my lab machine. When I connected via Opsware Global... (0 Replies)
Discussion started by: go2suresh1979
0 Replies

3. Shell Programming and Scripting

ps returning more process ids

Please help me with this question I have a tantan.sh under /home/mydir which is a caller to another script "tantan.sh" under /home/anotherdir ----------------------------------------------------------- /home/mydir/tantan.sh ------------------------------------------------------------... (6 Replies)
Discussion started by: guruincredible
6 Replies

4. UNIX for Advanced & Expert Users

Grep --byte-offset not returning the offset (Grep version 2.5.1)

Hi, I am trying to get the position of a repeated string in a line using grep -b -o "pattern" In my server I am using GNU grep version 2.14 and the code is working fine. However when I am deploying the same code in a different server which is using GNU grep version 2.5.1 the code is not... (3 Replies)
Discussion started by: Subhamoy
3 Replies

5. UNIX for Dummies Questions & Answers

Find command returning bad status--

would like to remove the post (8 Replies)
Discussion started by: vk39221
8 Replies

6. UNIX for Advanced & Expert Users

Grep returning partial lines due to special characters

Hey guys, I have a file with an ID which I'm using to grep out the original record from another file. Problem is I have special characters in the original file, and grep is returning only a partial record. How can I get around this? Appreciate your help! Pete (3 Replies)
Discussion started by: peteroc
3 Replies

7. Shell Programming and Scripting

Grep command to show only process name

Can I modify the grep command to show only a process name? Currently I run ps -efa | grep chk_web to get the following: mousr 3395 1 0 09:36:06 pts/10 0:00 sh /var/opt/scripts/chk_web.sh Can this be changed in any way to get only: /var/opt/scripts/chk_web.sh or chk_web.sh. I... (3 Replies)
Discussion started by: runnerpaul
3 Replies

8. Shell Programming and Scripting

returning status of a command

Hello gurus, Tired of using $? to view the execution status of the previous command. how can I get the status directly? definitely this is not working, if ] then fi (6 Replies)
Discussion started by: biglau
6 Replies

9. UNIX for Advanced & Expert Users

find command not returning any result

I am looking for all the header files (*.h).. which as per documentation of the UNIX system shouldbe there. I am using find / -name *.h -print But it does't give anything. My question is under what condition the "find" condition will fail to find the file? What is the work around. ... (4 Replies)
Discussion started by: rraajjiibb
4 Replies

10. UNIX for Dummies Questions & Answers

SED Command Returning a Blank File

I have a file called get_columns.sh that I would like to replace $2 with $3. I have the following sed command written that works sed s/'$3'/'$2'/g get_columns.sh > output.txt However, when I try the command below, the file is empty. sed s/'$3'/'$2'/g get_columns.sh > get_columns.sh ... (2 Replies)
Discussion started by: djschmitt
2 Replies
Login or Register to Ask a Question