OT: bash vs. ksh subprocess counts

From: Herring Dave - dherri <Dave.Herring_at_acxiom.com>
Date: Sun, 15 Apr 2012 17:45:08 +0000
Message-ID: <BD475CE0B3EE894DA0CAB36CE2F7DEB4455C9123_at_LITIGMBCRP02.Corp.Acxiom.net>



I realize this is way off topic (probably should be titled "WOT:...") for Oracle but #1, I don't currently belong to any good linux/redhat forums and #2, the issue found was from an Oracle maint. script :-) Anyway, I'm on a RHEL 4.6 server (2.6.9-67.0.22.ELlargesmp) and noticed a given DBA maint script wasn't running. It turns out that the only difference between when it last ran and now is someone changed the shell to be "bash" -> #!/bin/bash vs. #!/bin/ksh. The script has a little if-test to start with, used as a way to determine if a previous iteration of the job is still running:

if [ `ps -ef|grep -cw $0` -gt 3 ]; then

   echo "$0 is already running"
   exit 2
fi

The problem is that when this "ps ..." command stream is run within an if-test, it returns a value 1 higher than under "ksh". So when run out of cron it returns 4 under "bash" and 3 under "ksh". I added "set -x" right before this command and here are the results:

                (under ksh)

+ grep -cw /home/test.sh
+ [ 3 -gt 3 ]

(under bash)
++ ps -ef
++ grep -cw /home/test.sh

+ '[' 4 -gt 3 ']'

This change only happens when running that command stream as part of an if-test. So "ps -ef|grep -cw $0" returns "3" but "if [ `ps -ef|grep -cw $0` -gt 3 ]" evaluates to "4". Am I interpreting this correctly in saying that bash forks another process when evaluating a command as part of an if-test while ksh does not? Is there a more general way of explaining this difference is shell processing?

DAVID HERRING
DBA
Acxiom Corporation
EML dave.herring_at_acxiom.com
TEL 630.944.4762
MBL 630.430.5988
1501 Opus Pl, Downers Grove, IL 60515, USA WWW.ACXIOM.COM<http://www.acxiom.com/>

The information contained in this communication is confidential, is intended only for the use of the recipient named above, and may be legally privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please resend this communication to the sender and delete the original message or any copy of it from your computer system. Thank you.

--
http://www.freelists.org/webpage/oracle-l
Received on Sun Apr 15 2012 - 12:45:08 CDT

Original text of this message