关于后台程序的疑惑
- 543082593
- 帖子: 234
- 注册时间: 2008-11-07 8:41
关于后台程序的疑惑
后台一个进程 比如 firefox&
打开一个终端 然后输入
firefox&
然后 我在此终端输入 exit
则终端本身退出 firefox正常
运行 而我直接关闭终端 就是
鼠标点击那个关闭按钮
firefox也退出了
如果第二种情况我这么理解的话 firefox是bash的子进程 我关闭了终端也就是
终止了bash这个父进程 自然firefox属于bash子进程 也被关闭 那么第二种
情况也就有了解释
可是 我直接输入exit 也是退出父进程bash 但是 子进程firefox怎么没被终止呢
难道是 这里面有什么特殊机制吗
刚又试了一下 nohup firefox& 这个时候 直接关闭终端 firefox不会退出
还有一种情况 我打开 ooffice 和 picasa的时候 直接在终端输入 ooffice 或者
picasa 这个时候 用pstree看下进程树 发现 picasa的直接父进程是 init 而不是
bash 而当然 直接关闭终端 不会退出 picasa
这又是为什么 ?
打开一个终端 然后输入
firefox&
然后 我在此终端输入 exit
则终端本身退出 firefox正常
运行 而我直接关闭终端 就是
鼠标点击那个关闭按钮
firefox也退出了
如果第二种情况我这么理解的话 firefox是bash的子进程 我关闭了终端也就是
终止了bash这个父进程 自然firefox属于bash子进程 也被关闭 那么第二种
情况也就有了解释
可是 我直接输入exit 也是退出父进程bash 但是 子进程firefox怎么没被终止呢
难道是 这里面有什么特殊机制吗
刚又试了一下 nohup firefox& 这个时候 直接关闭终端 firefox不会退出
还有一种情况 我打开 ooffice 和 picasa的时候 直接在终端输入 ooffice 或者
picasa 这个时候 用pstree看下进程树 发现 picasa的直接父进程是 init 而不是
bash 而当然 直接关闭终端 不会退出 picasa
这又是为什么 ?
fall again
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
- O_O_BOT
- 帖子: 2461
- 注册时间: 2009-05-20 19:32
Re: 关于后台程序的疑惑
问题太长 看了 一句 就看不下去了。
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
- slax
- 帖子: 1099
- 注册时间: 2009-08-17 3:52
Re: 关于后台程序的疑惑
不懂
但想了解
但想了解
We believe that the internet should be public, open and accessible.
软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。
iceplayer! linux音乐新体验~ 最新版本4.0.5-20110520已更新!viewtopic.php?f=137&t=252461
想要iceplayer 测试版麼?加入QQ群80071264吧,在code.google也可找到
http://www.iceplayer.org/
http://jasy.ice.blog.163.com/
软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。
iceplayer! linux音乐新体验~ 最新版本4.0.5-20110520已更新!viewtopic.php?f=137&t=252461
想要iceplayer 测试版麼?加入QQ群80071264吧,在code.google也可找到
http://www.iceplayer.org/
http://jasy.ice.blog.163.com/
- 懒蜗牛Gentoo
- 论坛版主
- 帖子: 7353
- 注册时间: 2007-03-02 17:36
- 系统: Linux Mint
- c\nc
- 帖子: 231
- 注册时间: 2007-12-25 12:51
Re: 关于后台程序的疑惑
不知道为什么
这个机制应该和 X 有关系,有 GUI 的程序才不会因为 exit 而跟着退出,没有 GUI 的程序在后台工作的时候是不允许 exit 的。
这个机制应该和 X 有关系,有 GUI 的程序才不会因为 exit 而跟着退出,没有 GUI 的程序在后台工作的时候是不允许 exit 的。
- O_O_BOT
- 帖子: 2461
- 注册时间: 2009-05-20 19:32
Re: 关于后台程序的疑惑
此处是因为 firefox 在bash 主动的 exit之后 变成的打开一个终端 然后输入
firefox&
然后 我在此终端输入 exit
则终端本身退出 firefox正常
孤儿进程 会被init 接管 所以 很正常
点x 时 singup信号 发出 导致bash 退出 bash又发singup给各个job 导致firefox进程退出运行 而我直接关闭终端 就是
鼠标点击那个关闭按钮
firefox也退出了
刚又试了一下 nohup firefox& 这个时候 直接关闭终端 firefox不会退出
nohup 忽略了 singup信号
还有一种情况 我打开 ooffice 和 picasa的时候 直接在终端输入 ooffice 或者
picasa 这个时候 用pstree看下进程树 发现 picasa的直接父进程是 init 而不是
bash 而当然 直接关闭终端 不会退出 picasa
这又是为什么
有可能 这类程序 主动 作了 与bash进程的 脱离
fork一个进程A fork一个子进程B 结束A B成孤儿 归init管
上次由 O_O_BOT 在 2009-10-12 17:35,总共编辑 2 次。
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
- c\nc
- 帖子: 231
- 注册时间: 2007-12-25 12:51
Re: 关于后台程序的疑惑
想起来了,gvim 也是这样的。O_O_BOT 写了:还有一种情况 我打开 ooffice 和 picasa的时候 直接在终端输入 ooffice 或者
picasa 这个时候 用pstree看下进程树 发现 picasa的直接父进程是 init 而不是
bash 而当然 直接关闭终端 不会退出 picasa
这又是为什么
有可能 这类程序 主动 作了 与bash进程的 脱离
fork一个进程A fork一个子进程B 结束A B成孤儿 归init管
- O_O_BOT
- 帖子: 2461
- 注册时间: 2009-05-20 19:32
Re: 关于后台程序的疑惑
接下来的问题就是为什么 第一种情况不会收到sinup 第二种情况会收到sinup
http://blog.csdn.net/cugxueyu/archive/2 ... 46565.aspx
此文章说的很清楚 就懒得重复了。
但其中有个地方不对 job 是归shell管的 不是归session管 虽然属于session.
job 收不收到singup 由sh决定
此处是由于bash是session首进程 所以受到singup -> job firefox& 也接着收到singup
The shell exits by default upon receipt of a SIGHUP. Before exiting, an interac-
tive shell resends the SIGHUP to all jobs, running or stopped. Stopped jobs are
sent SIGCONT to ensure that they receive the SIGHUP. To prevent the shell from
sending the signal to a particular job, it should be removed from the jobs table
with the disown builtin (see SHELL BUILTIN COMMANDS below) or marked to not
receive SIGHUP using disown -h.
http://blog.csdn.net/cugxueyu/archive/2 ... 46565.aspx
此文章说的很清楚 就懒得重复了。
但其中有个地方不对 job 是归shell管的 不是归session管 虽然属于session.
此句不准确终端关闭时,该信号被发送到session首进程以及作为job提交的进程(即用 & 符号提交的进程)
job 收不收到singup 由sh决定
此处是由于bash是session首进程 所以受到singup -> job firefox& 也接着收到singup
The shell exits by default upon receipt of a SIGHUP. Before exiting, an interac-
tive shell resends the SIGHUP to all jobs, running or stopped. Stopped jobs are
sent SIGCONT to ensure that they receive the SIGHUP. To prevent the shell from
sending the signal to a particular job, it should be removed from the jobs table
with the disown builtin (see SHELL BUILTIN COMMANDS below) or marked to not
receive SIGHUP using disown -h.
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
- 543082593
- 帖子: 234
- 注册时间: 2008-11-07 8:41
Re: 关于后台程序的疑惑
恩 明白了O_O_BOT 写了:此处是因为 firefox 在bash 主动的 exit之后 变成的打开一个终端 然后输入
firefox&
然后 我在此终端输入 exit
则终端本身退出 firefox正常
孤儿进程 会被init 接管 所以 很正常
点x 时 singup信号 发出 导致bash 退出 bash又发singup给各个job 导致firefox进程退出运行 而我直接关闭终端 就是
鼠标点击那个关闭按钮
firefox也退出了
刚又试了一下 nohup firefox& 这个时候 直接关闭终端 firefox不会退出
nohup 忽略了 singup信号
还有一种情况 我打开 ooffice 和 picasa的时候 直接在终端输入 ooffice 或者
picasa 这个时候 用pstree看下进程树 发现 picasa的直接父进程是 init 而不是
bash 而当然 直接关闭终端 不会退出 picasa
这又是为什么
有可能 这类程序 主动 作了 与bash进程的 脱离
fork一个进程A fork一个子进程B 结束A B成孤儿 归init管
fall again
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
smooth criminal
they don't care about us
billie jean
beat it
dangerous
the lost children
childhood
ben
i will be there
speechless
she is out of my life
rock with you
...
LOVE U FOREVER
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
- O_O_BOT
- 帖子: 2461
- 注册时间: 2009-05-20 19:32
Re: 关于后台程序的疑惑
不完全准确xhy 写了:取决于子进程如何处理SIGNAL
在情况一 firefox没有收到singup信号
情况2 收到了singup 默认行为是中断
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录
http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]