exec and dead children

Nils Kassube kassube at gmx.net
Fri Dec 4 07:46:56 UTC 2015


Nils Kassube wrote:
> Karl Auer wrote:
> > I have a bash script which starts firefox:
> >    #!/bin/sh
> >    nohup /usr/bin/firefox \
> >    
> >          -new-window URL1 \
> >          -new-window UR2  \
> >          [etc] > /dev/null 2>&1 &
> >    
> >    /bin/sleep 20
> > 
> > I start this script from a terminal. To avoid having an unused
> > terminal window hanging around afterwards, and also to avoid having
> > to press CTL-D, type "exit" or click the close widget, I start this
> > 
> > script using exec:
> >    exec myscript.sh
> > 
> > If I don't put that delay at the end of the script, the new firefox
> > windows die with the script. Actually, they never really get time to
> > open. If I don't use nohup, they die regardless of the delay.
> > 
> > Why is this so?
> 
> I think it happens because with the "&" the new nohup process gets
> started in the background and your script continues. When it reaches
> the end, it exits normally. However the background process of nohup
> has not yet reached the point where it has started firefox and
> returns, so it dies together with the end of the script.
> 
> > Is there some way I can avoid having to insert that
> > delay?
> 
> Did you try the "wait" command instead of the sleep command. Then the
> script should exit as soon as possible.

Sorry, forget about the "wait" command - it doesn't work.

However there is a way that does work:

#!/bin/sh
firefox $ARGS <&- >&- 2>- &

Here the "<&-" closes standard input, ">&-" closes standard output and 
"2>-" closes standard error. The "<&-" would be sufficient, but using 
the other two, you avoid garbage output similar tou your version of 
">/dev/null 2>&1".


Nils





More information about the ubuntu-users mailing list