I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program.
I want 1st script to wait until the 'C' program completes.
I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second script(child script) to complete
Can any one help me, how to get the process id for the 'C' program in unix shell script or is there any other way to make the parent script to wait for the child process.
Where did you use wait? Only the parent process can wait for any child, so if you start the program in the second script, you'll have to wait for it in the second script, not the first.
Another way would be to save the PID in a temporary file, which is then read in the first script. Then the first script checks the process list until it's no longer listed, eg:
while [ "$( ps -p ${PID} >/dev/null 2>&1; echo $?)" == "0" ]
do
sleep 1
done
yes it will help, our script is running in production and we dont have the permission to edit the second script (ie. C program). we have to achieve this thru first script only.
If the second script doesn't save the PID anywhere, and you're not allowed to change that, your only chance would be to get the PID from a process listing, eg
ps -ef | awk '/cron/ && !/awk/ {print $2}'
assuming that the C program has a unique enough name and that there's always only one instance running. You can then wait for that PID using the code posted above