How is & implemented in bash under the hood?
& # 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.
精彩评论