getting exit status from background job in sh

Maarten Litmaath maart at nat.vu.nl
Thu Jun 6 05:25:38 AEST 1991


In article <rodgers.676057135 at clausius.mmwb.ucsf.edu>,
	rodgers at clausius.mmwb.ucsf.edu writes:

>[...] we have modified it a bit so that it
>can, upon specification of an option, save the status in a file, which is
>useful if the rsh command is placed in the background from within a script.
>One can then carry on with other work, then use the wait command to ensure
>that rsh is done, read the exit status from the file, and act appropriately.

You need not modify `ersh' to accomplish what you want.
This is how to do it in the Bourne shell:

	ersh machine cmd < input > output 2> errors &
	pid=$!		# remember the process ID
	# lots of other commands
	wait $pid	# wait for the specified process
	status=$?	# the exit status of the process is returned

If you _must_ use a file, use the following:

	(ersh machine cmd redirections; echo $? > status_file) &

In the csh you would have to resort to this:

	((ersh machine cmd < input > output) >& errors; \
		echo $status > status_file) &

>So on to a related problem: if one puts a LOCALLY executed command into the
>background from within a script, then later issues a wait command so as to be
>able to do something with output from the command, how can one cause the exit
>status for the background command to have been saved in a file? 

That question has been answered by now.



More information about the Comp.unix.shell mailing list