Shell script runs fine in Solaris, in Linux hangs at wait command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script runs fine in Solaris, in Linux hangs at wait command
# 8  
Old 10-28-2010
I recall on one O/S the ksh would run ksh scripts in the same pid, so you would see interactive background with wait, but in Solaris it is always a child process, and waits only for its own children. I ended up putting () around lines 2-$ to keep my environment from getting scrambled by my scripts.
# 9  
Old 10-28-2010
SunOS xxxxxx 5.8 Generic_117350-25 sun4u sparc SUNW,Ultra-80

Linux yyyyyy 2.4.21-47.0.1.ELhugemem #1 SMP Fri Oct 13 17:48:02 EDT 2006 i686

---------- Post updated at 02:45 PM ---------- Previous update was at 02:42 PM ----------

i tried to enclose just while loop as well lines 2-$ within (), behaviour doesn't change.

---------- Post updated at 03:09 PM ---------- Previous update was at 02:45 PM ----------

Ok, I found a workaround to this problem.

i started collecting all my child jobs, wait only for those pid. this resolved my zombie wait

Code:
while loop
do
child_pids=

for loop
do
bg_work &
child_pids="$child_pids $!"
done

wait $child_pids
done

# 10  
Old 10-29-2010
I guess wait on LINUX waits for everything. I wonder if nohup helps to move the script away. It might be an interesting man page read or such, to find out whether it is waiting for all processes on the tty or on the process group. But yes, collecting pids and waiting for them one at a time is best, as you get the exit return $? of each child from "wait $child_pid".

If the exit status is not a biggie, or you check that through log files, you can skill the wait and monitor the children through shared stdout and stderr, like this:
Code:
(
this&
that&
the_other&
) 2>&1 | cat >>$shared_log

This monitors not only the children but their children and so on, as long as they do not redirect both stdout and stderr. Even when "wait $child_pid" returns, the child may have antecedents still running, background or up-pipeline processes that close stdout but do not immediately exit, or someone down-pipeline exits cutting them off! $! is just the parent or last in pipeline pid.
Code:
sleep 99 | sleep 5 & wait $!    # wait waits for sleep 5 but sleep 99 is still running.

(sleep 99 & sleep 5 ) & wait $!    # wait waits for sleep 5 but sleep 99 is still running.

The ability of processes other than $! to get errors not reported on $? is one reason to rely on logs, or write a very attentive wrapper script to keep an eye on the children and report $? for all. Sometimes I get really formal, for money and my job security and all that. This is fine for interactive, but not so wise unattended:
Code:
cmd1|cmd2|cmd3

Code:
>$fail_log
(
  cmd1
  zret=$?
  if [ $zret != 0 ]
  then
   echo cmd1 returned $zret >>$fail_log
  fi
 ) | (
  cmd2
  zret=$?
  if [ $zret != 0 ]
  then
   echo cmd2 returned $zret >>$fail_log
  fi
 ) | (
  cmd3 . . . .
 )

if [ -s $fail_log ]
then
 exit 1
fi


Last edited by DGPickett; 10-29-2010 at 12:52 PM..
# 11  
Old 10-29-2010
The ksh on Solaris is probably the old modified version of ksh88 that ships by default with Solaris.

What happens when you run the script on Solaris using /usr/xpg4/bin/sh?
# 12  
Old 11-01-2010
This might be a bug in the version of ksh that you have which is likely fixed in the current release.

I'm running 'Version JM 93t+ 2009-02-02' on some boxes, and 'Version JM 93t+ 2010-06-21' on most of my linux boxes. Testing on the older of the two it handled your script without any problems:

Code:
>>>start: Sun Oct 31 23:18:46 EDT 2010
jobs output
[2] +  Running                 <command unknown>
[1] -  Running                 <command unknown>
jobs -p  
Before entering parallel process  18154 
>>>finish: Sun Oct 31 23:18:46 EDT 2010

I added start/finish messages to show the delay, if there was any. There is a more recent release than the 6/21/2010 version; it can be pulled direcly from AT&T Labs-Research; AST software download

As a further test, I put this little script together that reads lines with one or more sleep times and sets that many async sleep processes going. It is similar to the script you are running and it seems to have no issues with a more recent version of ksh.

Code:
while read list
do
        for x in $list
        do
                echo "$(date) sleeping $x"
                sleep $x &
        done

        echo "$(date) waiting"
        wait
        echo "$(date) looping"
done <xx

# 13  
Old 11-01-2010
Your (agama) test script works fine too with the ksh version shipped with Solaris 10 (Version M-11/16/88i).
This User Gave Thanks to jlliagre For This Post:
# 14  
Old 11-01-2010
Sometimes I script parallel processing logging so it looks like it was done sequentially, both to keep from mixing line fragments and so as not to confuse the onlookers in their less sophisticated moments (-:
Code:
cmd1 >log1 2>&1 &
pid1=$!
 
cmd2 >log2 2>&1 &
pid2=$!
 
wait $pid1
zret1=$?
echo ==== cmd1 ====
cat log1
echo ===== cmd1 returned $zret1
 
wait $pid2
zret2=$?
echo ==== cmd2 ====
cat log2
echo ===== cmd2 returned $zret2
 
exit $(( $zret1 + $zret2 ))

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sql command inside shell script runs without giving anything back as outout

#!/bin/sh # This script returns the number of rows updated from a function echo "The execution is starting ....." sqlplus -silent $UP <<EOF set serveroutput on set echo off set pagesize 0 VAR no_rows_updated NUMBER; EXEC :no_rows_updated :=0; DECLARE CURSOR c_update is SELECT * FROM... (4 Replies)
Discussion started by: LoneRanger
4 Replies

2. Shell Programming and Scripting

In Shell Script Does Second Command Wait For First Command To Complete

Hi All, I have a question related to Shell scripting. In my shell script, I have following two commands in sequence: sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE mv $TEMPFILE $ORIGFILE... (3 Replies)
Discussion started by: angshuman
3 Replies

3. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

4. Shell Programming and Scripting

Part of the Shell script is not running via crontab, runs fine manually

Hello Team, As a part of my job we have made a script to automate a service to restart frequently. Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Discussion started by: gowthamakanthan
18 Replies

5. Shell Programming and Scripting

Script runs fine manually but not in crontab

Hello Guys, I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following. 1) When I manually execute following script it runs successfully with below output. bash-3.00# more smssend #!/bin/bash echo -e "<Request... (16 Replies)
Discussion started by: umarsatti
16 Replies

6. Shell Programming and Scripting

CRON shell script only runs correctly on command line

Hi, I'm new to these forums, and I'm hoping that someone can solve this problem... To make things short: I have DD-wrt set up on a router. I'm trying to run a script in CRON that fetches the daily password from my database using SSH. CRON is set like so(in web interface): * * * *... (4 Replies)
Discussion started by: louieaw
4 Replies

7. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

8. Shell Programming and Scripting

Script Runs fine but not giving any output

Hi, My script is running with no erros but not giving any output can anyonehelp. #!/bin/ksh . /home/application/bin/application.env OUTFILE=Result.txt PROD_PASSWORD=`${GET_PWD} -f ${PWD_FILE_PATH} -s ${PROD_SERVER} -u ${PROD_USER}` echo "1)To get the book last loaded details " read... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

9. Shell Programming and Scripting

Script runs fine, but not in a cron

Okay, I have the following script that runs fine from a command line as well as an executable .sh file. It just moves any file/folder with movie* in the name to a folder called _Movies. The issue I'm running into is when it's call from a cron. find /mnt/HD_a2/BT/complete -iname "movie.*" -exec... (4 Replies)
Discussion started by: sammyk
4 Replies

10. UNIX for Dummies Questions & Answers

Script runs fine on UNIX Server...Not through MSK Tool kit on Windows Server

I have a .sh script which was running fine on all the UNIX Servers (AIX, SunSolaris). The script requires two mandatory parameters and many optional parameters. Now at a different client place who are on a Windows Server, when I try to execute the script through MKS Toolkit, there are couple of... (5 Replies)
Discussion started by: madhunk
5 Replies
Login or Register to Ask a Question