UNIX下Job id的疑问
I asked a related question
'Difference between process group id and job id in Unix',
but I have a doubt that was not answered. In that answer, it was written that job id is built in data related to shell (kernel has nothing to do with it), so foreground / background is understanding of shell, but when we do "ps x
" then it display in stats as "R+"
or "R"
as foreground and background process respectively but ps
is executed by kernel so how does kernel know that job is back/foreground.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作业 ID 绝对是 shell 功能。
然而,操作系统有当前终端进程组ID的概念,shell也使用它来促进作业控制。与当前终端进程具有相同进程组 ID 的进程接收 SIGINT 等键盘信号,并能够在终端上执行 I/O。这些进程是前台进程。如果进程组ID不同,则该进程是后台进程。当进程在此概念中为前台进程时,ps 命令显示
+
。它仍然不需要了解有关 shell 实现的作业控制的任何信息。Job IDs are definitely shell features.
However, the operating system has the notion of current terminal process group ID, which is also used by the shell to facilitate job control. Processes which have the same process group ID as the current terminal process receive keyboard signal such as SIGINT and are able to do I/O on the terminal. These processes are foreground processes. If the process group ID is different, then the process is a background process. The ps command displays
+
when the process is a foreground process in this notion. It still does not need to know anything about job control as implemented by the shell.我不会说“内核与它无关”,因为 shell 使用内核中的例程来实现其目的。
shell 决定进程是前台还是后台,但内核也必须知道这一点,并且可以在 shell 询问时报告进程的状态。
I wouldn't say 'kernel has nothing to do with it' since the shell uses routines in the kernel to achieve its purposes.
The shell decides whether a process is foreground or background, but the kernel must be aware of it too, and can report the status of processes when the shell asks.