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.
views:
95answers:
2I 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.
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.