Xref: utzoo comp.unix.questions:26889 comp.unix.shell:891 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!fwi.uva.nl!casper From: casper@fwi.uva.nl (Casper H.S. Dik) Newsgroups: comp.unix.questions,comp.unix.shell Subject: Re: exit value (MORE INFO) Message-ID: <1462@carol.fwi.uva.nl> Date: 14 Nov 90 14:30:42 GMT References: <1990Nov12.110248@cs.utwente.nl> <1990Nov13.160213.15743@ssd.kodak.com> <1990Nov14.100834@cs.utwente.nl> Sender: news@fwi.uva.nl Followup-To: comp.unix.questions Lines: 62 stadt@cs.utwente.nl (Richard van de Stadt) writes: >With this posting I want to explain with an example why I want to know >the exit value of a process that was started in background. From reactions >of some of you (thank you very much) I understand that the question was a >bit vague. >First of all I'm not a newcomer to UNIX (know it since 1983). >I didn't ask how to get an exit value of a process, because I already >know that's in $?. I also know that the process id of the last process >started in background is in $!. In that case you know enough: wait [ n ] Wait for the background process whose process ID is n and report its termination status. If n is omitted, all the shell's currently active background processes are waited for and the return code will be zero. The solution would be: job & proc=$! rest ... wait $proc if [ $? = 1 ]; then ... job failed ... ; fi Or in your script: ------------------------------------------------------------------------ #! /bin/sh #name of script: floppyformat doit () { # a function attent /dev/dk1 #find out if -m option must be used (new floppy) case $? in 0) # not a new floppy dkformat /vol/name_of_floppy >/dev/null 2>&1 #no output on screen exitval=$? break ;; *) # a new floppy dkformat -m /vol/new_name >/dev/null 2>&1 & #no output on screen proc=$! sleep 10 # be sure process is started # actually done by looping on pid attent /dev/dk1 # give what dkformat is waiting for # wait # wait for format process to have finished wait $proc # wait for format process to have finished # exitval='exit_value_of_last_process_started_in_background' ;; exitval="$?" ;; esac case $exitval in 0) echo "Floppy was formatted successfully" ;; *) echo "Format process failed. Try other floppy" esac } # end of function echo -n "Insert floppy and press return " read return doit & #start format process in background and exit immediately ------------------------------------------------------------------------ -- Casper H.S. Dik, casper@fwi.uva.nl, NIC: !cd151