I'm implementing the logging solution presented here and I don't know if the following lines are required whenever I exit the parent bash process/script:

if [ -n "$teepid" ]; then
    exec 1>&- 2>&-  # close file descriptors to signal EOF to the `tee`
            #  command in the bg process
    wait $teepid # wait for bg process to exit
fi

Those lines can be found in the log() function and in the end of the script. I know that they're required in the log() function, but are they required at the end of the script?
In other words: Would my background job exit nicely without having the aforementioned code written before every exit command in my parent process?

link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

The process identified by PID $teepid is backgrounded using &. If you exit without waiting for that PID to finish, the only bad thing that will happen is the same thing that happens if you use & in the shell. You'll hit [Enter] at some later point and get pestered with a [1] {pid} exited (or something similar, can't remember precisely now) message before your next prompt line is displayed.

link|improve this answer
"If you exit without waiting for that PID to finish, the only bad thing that will happen is the same thing that happens if you use & in the shell." - What it means? – Dor Jul 15 '11 at 11:12
Try entering echo "hello" & from a shell prompt, hit ENTER twice, and you'll see what I mean. – ultrasawblade Jul 15 '11 at 13:03
Now I understand. So it's safe to remove those lines from the end of the script? – Dor Jul 15 '11 at 14:01
Sure, but you'll get that side effect if you run it from an interactive prompt. – ultrasawblade Jul 15 '11 at 14:29
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.