Je Rog
Je Rog

Reputation: 5993

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 how is it achieved?

Upvotes: 3

Views: 888

Answers (1)

Blagovest Buyukliev
Blagovest Buyukliev

Reputation: 43508

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.

Upvotes: 5

Related Questions