How to export a variable from a child process running in background to the parent

Hi All,

I have a script which calls a child script with a parameter to be run in the background

. childscript.ksh $a &

Can any one suggest me how do i export a variable from the child script to parent script?

Note that the child script is in background
If the child script is in foreground that is not an issue.

Also can any one suggest me how to get back the exit status (of say exit 0 ) from any of the functions in the child script to the parent script, again in this case the child script is running in the background.

Thanks

shell scripts are not supposed for IPC. they are just shell scripts.

you might find out the values of any of your childs variable by parsing /proc/[pid]/env in case you're on linux. also you functions may write variabes to a file to monitor the results.

you should use perl or at least c to do such things in a reliable manner

Hi demwz

I am basically not much of a Unix guy... and didn't understand much of what you said. But do you mean it is not possible, and i am working on Kshell.

But if you mean it is not possible...? Why is it so with a background process..that you are not able to export the varible

Parent Script
-----------------
. childscript.ksh arg &
wait
echo $a -------------------- This echo statement is not getting displayed?
exit 0 Any simple idea
---------------

Child script
------------

echo $#
echo $1
a=10
export a
exit 0
-------------------------

Can you explain this in a bit simple manner?

exported variables are inherited from parent to child and not the other way round.
Tough there is always a way shell ist not designed to do inter Process communication (IPC) this is normaly done by shared memory access or Unix domain sockets.
your example is quite simple bcs the child ends very fast.
echo $(./child.sh)
but if you want to acces data from a running child it gets complicated.
you may let the child write to a file or fifo which is read by the parrent.