Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ksh spawning multiple processes

Status
Not open for further replies.

fisa

Programmer
Nov 28, 2003
19
0
0
GB
Hi friends,
I have a shell script runnung using ksh on my hp-ux box. When the script is running, I have noticed that
"ps -ef | grep <script name>" gives multiple entries. I mean, sometimes i can see two same instances of the script and some other times 3 or 4. What could be the reason for this? Note that the script in turn does not invoke any other shell scripts. Please revert back to me in case you require any further details on this. Please do shed some light as this is a bit urgent.

Thanks in advance
Fiza
 
do you have #!/bin/sh as the first line of your script?

that might explain seeing it twice. seeing it 3-4 times? sounds like other iterations are still running... check the process time for all entries and see when these things started...

it's a place to begin looking...

I once saw a script that had the #! notation for the shell to spawn and followed it with the script name (as an internal label).. so it looked like this...

#!/bin/sh thescript.sh

so, what happened was that you run the script, which in turn ran the script... and they told two friends... and so on...

anyway... hope that helped...


...Steve...
 
Hi Steve,

Thanks for the info. Let me give more details on the same.

The multiple processes that are running are(update.sg is the script name)

[hlk150]/scripts $ ps -ef | grep update
10195 1 79 21:21:28 ? 115:21 /bin/ksh ./update.sh
21947 21946 0 19:19:35 ? 0:00 /bin/ksh ./update.sh
21938 5564 0 19:19:35 pts/tb 0:00 grep update
21948 21946 0 19:19:35 ? 0:00 /bin/ksh ./update.sh
21946 10195 1 19:19:35 ? 0:00 /bin/ksh ./update.sh

Here only the first entry shows the actual staring time of the script. Other entries show the current server time as the staring time. Also I am not sure about the significance of 0:00 time shown in other entries.

The scripts starts this way.

#!/bin/ksh
PATH=.:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:/etc:/kbase/scripts:/kbase/intray/soar
export PATH

Clearly the script does not have the script name along with the #!/bin/ksh statement.
Also i have made it sure that only one time the script is invoked. After that only the spawning takes place.

Hope these details will help you shed more light in to the matter..........
 
fisa,

The easiest way to troubleshoot your problem would be if you posted your script so that someone could perhaps determine what is going wrong. Is the script executing from cron or are you executing it manually? Try running the script in verbose mode with the ksh -x or ksh -v commands.

Ex. From the command line, type: ksh -x ./update.sh[b/] and see if you notice anything that should not be happening.

John
 
The 0.00 time shown for every entry except the initial one refers to the time the script has spent executing.

Interesting - would it be possible to post your script here?

One possibility is that the script is running - or trying to run - an external command, which are run in child shells initially. These child shells go away quite quickly though.

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Hi All,

Sorry for the delay to put in my comments here as i was indisposed for the last week.
As you suggetsed it may be better if i could post the script here. But I am afraid as this is a bit confidentail stuff.

Let me give more inputs towards understanding the script.

The script starts this way.

#!/bin/ksh
PATH=.:/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin:/etc:/scripts:/intray/update
export PATH


The script starts with a for loop that picks up *.zip files from a specified directory. They are unzipped using unzip - Uo command. Each *.xml file is picked up from the unzipped file and according to the values of certain tags they are processed. After processing the xml files are moved to a target location.
After processing all the zip files the script ends after calling another script having a different name.

I have noticed that when multiple processes are noticed the second script(which is called by my script at the end) is not running.
Mike, can you tell me what are the possibilities of the script calling certain external commands that run in other child shells? What exactly do you mean by external commands?

Thanks a lot for your continued support.....

 
Unix processes run external commands, like unzip for instance, by calling fork(), this creates a copy of the currently running process, and then by calling exec(), which replaces the copy of the currently running process with the external command.

It's unlikely but possible that you're running ps at just the right moment to see the copies before they call exec().

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top