Chet Ramey <chet.ra...@case.edu> writes: > On 4/20/23 1:53 PM, Dale R. Worley wrote: >> How difficult would it be to add an optional timeout argument to the >> "wait" builtin? > > Try a variant of this. > ...
My interest here isn't "Can I accomplish this task with Bash?" but quite literally, Can I make this a *feature* of Bash so I don't have to set up the mechanics? (I already know of a couple of other ways to do it with Bash.) An interesting point, which you may or may not have intended, was that this Bash code can be turned into C code fairly easily: Fork a subprocess to wait for the timeout and when it fires, send USR1 to Bash. Then make sure Bash is waiting for the timeout subprocess as well as whatever other children it should be waiting for. My *reflex* is that this is a really heavyweight implementation, but on consideration, I think I'm wrong: fork() is cheap in Un*x, indeed, that may have been its central design innovation, make processes cheap and use them freely. So then fleshing this out, let me ask: Is it reasonable to add an optional timeout to the "wait" builtin using this mechanism? Dale