read vs sleep in bash scripting
This is a simple question. If I use the read
command in bash script, while the script is waiting for the input command, what really happens, is the memory consumption reduced to a sleep st开发者_运维知识库ate, like if we use the sleep command?
The memory consumption is not affected at all, the thing that happens in both cases is that the shell process changes its state from runnable to suspended.
In the case of read
, the shell process goes in kernel space to read the user input, and is later rescheduled whenever data is available.
sleep
voluntarily yields to kernel space where the process is suspended, and it is rescheduled after the timeout has passed.
精彩评论