开发者

read vs sleep in bash scripting

开发者 https://www.devze.com 2023-04-12 20:00 出处:网络
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开发者_运维知

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号