开发者

How is & implemented in bash under the hood?

开发者 https://www.devze.com 2023-04-01 14:51 出处:网络
&# disown the functions As we all know & put a task into background, and most importantly disowns the task.
&    # disown the functions

As we all know & put a task into background, and most importantly disowns the task.

But 开发者_Go百科how is it achieved?


Without a &, the shell forks itself, calls execve in the child process to start the task, and waits via wait or waitpid for the child to terminate (which suspends the shell), not doing anything else than that.

When starting a background task, the shell forks itself again, calls execve to start the task in the child process, but doesn't wait for its termination and rather return the control immediately after the start of the task.

0

精彩评论

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

关注公众号