issue with grep command

i am using 'psu' to grep the status of a process like below :-
psu|grep -i agentf
29559 29552 0 00:53:05 ? 0:57 gn1avm_agent -n AGENTF1
28946 1 0 00:51:31 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1
29552 28946 0 00:53:05 ? 0:00 /bin/ksh /olclocal/fs_users/tksfr01/abp_home/core/bin/gn1_preAvm_Ksh -b gn1avm_agent -c -n AGENTF1

out of these three process, RED process(first process) is IMP for me , i want to track this but problem is that - Orange colour process(2nd process) is also having same search pattern and it also comes with grep command .this orange process comes UP first and so my script/job checking 'psu' status shows - it's UP. but in fact , till now only Orange process is up not RED , RED process is still coming up and takes 2 more mins.

i want to check right status of RED process at right time.
if i use below command:-
psu | grep 'gn1avm_agent -n AGENTF1' | grep -v '\-c' | grep -v grep -> it gives right status , but now , it wil lbe treated as
psu | grep �gn1avm_agent -n AGENTF1| grep -v '\-c'' which will return nothing.
so how to grep it , my script checking this status is :-
DaemonPIDs=`ps -ex | grep -v -e grep | grep "${DaemonExeName}

ps -ex | grep -v -e grep | grep "gn1avm_agent -n AGENTF1"
29559 ? 0:59 gn1avm_agent -n AGENTF1
28946 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1

+ CheckDaemonStatus
+ + ssh host -l account -qn ps -ex
+ grep -w gn1avm_agent -n AGENTF1
+ grep -v -e grep -e amc1_vrts_gen_monitor_ksh -e opcmon

so hot to get rid of this problem , pls suggest.

ps | grep "[g]n1avm_agent -n"

[g] just matches g, but won't match itself so you can take out the grep -v grep.

thats ok, but my problem is not to get rid of grep process. above i mentioned two process , red and orange , they r using same search pattern , i want to check the UP status of red process, which is taking more time compared to orange colour process and so script shows its UP as soon Orange process comes up.
i want to get Actual Status of Red process.

It won't match the orange process, or the third process, because of the -n. It will only match the red process.

see now , still showing both:-
psu|grep "[g]n1avm_agent -n"
tksfr01 29559 29552 0 00:53:05 ? 1:04 gn1avm_agent -n AGENTF1
tksfr01 28946 1 0 00:51:31 ? 0:31 gnavm_ewd -b gn1avm_agent -n AGENTF1 -c -n AGENTF1
it will not work , the whole searching string is common in both process "gn1avm_agent -n AGENTF1"

I see what you mean now.

The usual way to track these things would be to have the program in question generate a PID file, which you can use to see if the PID is still valid. Even if the program doesn't do that, you can use things like start-stop-daemon to do so for you.

Failing that:

psu | grep "[g]n1avm_agent -n AGENTF1$"

yeah , i think this looks fine , let me try :slight_smile:
Thanks a lot !!!