There are two aspects of foreground/background in the Posix *nix operating systems.
One is absurdly simple: the shell or some other parent process either is or is not waiting (via some variation on wait(2)
) for the child to finish. If the parent is waiting, it's foreground. If it's not, it's background. In the original versions of *nix, this was the entire story. As you can see, the shell actually did less work to implement the magic % command &
pattern than just % command
, yet few other systems could do this.
Now, that leaves a few loose ends. Processes have controlling terminals and terminals have process groups. There are session leaders and process group leaders. It is nice to have signals directed simultaneously at just, say, one connected pipeline in the background. Jobs in the background that attempt terminal I/O get a signal. When users log out the OS may want to reclaim a virtual or physical terminal for security and in order to give the next user unobstructed access. So the entire story gets rather more complex. 4.1BSD
introduced essentially the present-day full-blown job control mechanism.
I've given you the keywords to search for if you want to know at a more detailed level than this.