Background processes

How do you capture the return code from a background process?
I am dumping data to a fifo and then processing it in a c program.
I need to know that the sql finished successfully to ensure no missing data. Thanks.

ex.
sqlplus user/password < get_data.sql > data_fifo.txt &
bin/process_data data_fifo.txt
RC=$?
if [ $RC -eq 0

and so forth....

You could just send some sort of message wrapper
to the FIFO that your program can read.
Effectively setting up an application level
protocol... SYN SYN SOH... sqlplus data ...EOD

Also, you could write the shell script to launch
your C program in the background and grab the
PID of that program (i.e. PROGPID=$!). You
can the send a signal (see kill(1) man page) to
your program to tell it all is OK or not. Your
code would of course have to properly handle the
signals you choose to send (see signal(5) man
page).

In ksh at least this is easy. First when you background a job, save the value of $! which will be the pid of the background job. The background job will eventally finish and become a zombie. It will stay a zomblie until the parent waits for it and retrieves the exit code. In ksh, this is done with the "wait" command. The exit code of the wait command will be the exit code of the process that was waited for. This sounds complex but try this script:

#! /usr/bin/ksh
true &
pid=$!
wait $pid
rc=$?
echo rc = $rc

false &
pid=$!
wait $pid
rc=$?
echo rc = $rc

exit 0

However, in your sample, I don't see why you bothered to background the job, since the next step is to ask if it worked. Why not just leave it in the foreground? Well, maybe it was just an over-simplified example much like my own sample code.