Why do shells ignore SIGINT and SIGQUIT in backgrounded processes?

后端 未结 1 1019
醉话见心
醉话见心 2020-12-03 17:48

If I background a processes in a script or a -c snippet, the backgrounded processes ignores SIGINT and SIGQUIT:

Example:

$ alias ps=\'ps -o pid,ppid,         


        
相关标签:
1条回答
  • 2020-12-03 18:11

    When a shell runs a program in the background, the background process is not supposed to be tied to the original shell any more -- the shell can exit or be killed, and the background process should continue running.

    If the shell is interactive and job control is being used, it puts the background process in a separate process group, so signals sent to the shell process group don't affect it.

    But when job control is not being used, which is the default in non-interactive shells, the background process is in the same process group. To avoid the background process receiving keyboard signals that are just intended for the shell, it apparently ignores those signals in those child processes.

    0 讨论(0)
提交回复
热议问题