[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wait inside subshell waits for sibling

From: Robert Elz
Subject: Re: wait inside subshell waits for sibling
Date: Mon, 24 Oct 2022 13:47:10 +0700

    Date:        Mon, 24 Oct 2022 04:25:44 +0200
    From:        Emanuele Torre <torreemanuele6@gmail.com>

  | bash performs an optimisation that runs redirections applied to simple
  | commands that run external programs, or subshell compound commands after
  | the fork(). (to avoid having to restore file descriptors after running
  | the command.)

It need not make a difference.   The wait command is not intended to
be just the wait(2) (or wait(3) whichever it is on the system in
question) system call (or wrapper around another system call).

There's no reason that wait (the command) cannot check for candidate
jobs which are still running, and wait for any of those, and then
return as soon as there are none left.   That the shell happens to
have forked other processes for its own reasons should make no
difference at all.

  | This causes other weird pitfalls, e.g. the following script loops
  | infinitely, and always runs `sleep 1 > /tmp/file1':
  |     i=0
  |     while [ "$i" -lt 10 ]
  |         do sleep 1 > "/tmp/file$(( ++i ))"
  |     done

That is an entirely different issue, and is working as is supposed
to work.   That it isn't what some people might expect is irrelevant.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]