Shell Script Produces Several Child Processes

(Doc ID 2019853.1)

Last updated on JANUARY 02, 2016

Applies to:

Solaris SPARC Operating System - Version 8 2/04 U8 and later
Information in this document applies to any platform.

Symptoms

 A shell script may try to verify that it is the only copy running by doing something similar to "ps -ef | grep script | grep -v grep | wc -l" and expecting the value to be 1

An example would be:

 

Note the shell can be /bin/sh or /bin/bash or other shell, they should all work similarly

 

$ cat test-ra.sh
#!/bin/sh

working_num=`ps -ef |grep test-ra.sh |grep -v grep|wc -l`
if test $working_num -gt 1
then
echo "Another process_check.sh script is still working..."
exit 1
fi

  

 

Changes

 N/A or anything that changes the timing

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms