Discussion:
[Help-bash] Why is sleep not a builtin
Jesse Hathaway
2018-06-22 14:30:37 UTC
Permalink
I was profiling some bash code and found thousand of execve's running
sleep. Though the agresssive
Jesse Hathaway
2018-06-22 14:33:53 UTC
Permalink
sorry hit sent accidentally,

I was profiling some bash code and found thousand of execve's running
sleep. Though the aggressive sleeps were not the cause of the problem, as
they were used to wait for a background job to complete. I was curious as
to why sleep is not a bash builtin so as to avoid all the forks, when waiting
for another process to complete? The developer could have used wait, but
then they can't provide any progress feedback to the user.
Post by Jesse Hathaway
I was profiling some bash code and found thousand of execve's running
sleep. Though the agresssive
Greg Wooledge
2018-06-22 15:30:16 UTC
Permalink
Post by Jesse Hathaway
I was curious as
to why sleep is not a bash builtin so as to avoid all the forks, when waiting
for another process to complete? The developer could have used wait, but
then they can't provide any progress feedback to the user.
You can. You just have to run the notification as a second child process
that you terminate when you're done waiting for the first child process.

I'm assuming the notification process is a spinner, or a stream of dots,
or something of that nature. It's commonly done.
Jesse Hathaway
2018-06-22 15:42:10 UTC
Permalink
Post by Greg Wooledge
You can. You just have to run the notification as a second child process
that you terminate when you're done waiting for the first child process.
I'm assuming the notification process is a spinner, or a stream of dots,
or something of that nature. It's commonly done.
Thanks Greg, I'll give that a try, though I am still curious as to why it is
not a builtin, as people seem to jump through crazy hoops to avoid using
it, e.g.
https://unix.stackexchange.com/questions/68236/avoiding-busy-waiting-in-bash-without-the-sleep-command
Loading...