开发者

Moving Active jobs in a Shell from the Background to Foreground and the Other Way Around

This section of the glibc manual explains job control, but unless I am missing it, it doesn't explain how to implement the开发者_如何学C ability to move a job that has already launched into the background or foreground.

Can anyone give me a basic example, overview, or a link that explains how this works?

I don't mean how to do this in a shell, but rather how to implement it when writing a shell.


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.


I don't mean to be a smart ass, but have you tried looking in:

http://ftp.gnu.org/pub/gnu/bash/bash-4.0.tar.gz

;-)

-Oisin

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜