UNIX下Job id的疑问

发布于 2024-08-07 02:24:57 字数 379 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

且行且努力 2024-08-14 02:24:57

作业 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.

泛滥成性 2024-08-14 02:24:57

我不会说“内核与它无关”,因为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文