据我所知,从书籍和bash手册中可以看出.当用户从bash注销时,如果用户未使用nohup或disown,则用户启动的所有后台作业将自动终止.但今天我测试了它:
终端中有两个选项卡,其中一个我创建了一个名为test的新用户并以test身份登录
su - test
Run Code Online (Sandbox Code Playgroud)开始写一个剧本.
cat test.sh
#!/bin/bash
sleep 60
printf "hello world!!"
exit 0
./test.sh &
Run Code Online (Sandbox Code Playgroud)之后我退出测试并关闭了标签
这是怎么回事?
jil*_*les 14
是否在退出时终止后台作业取决于shell.Bash通常不会这样做,但可以配置为登录shell(shopt -s huponexit).在任何情况下,在控制进程(例如登录shell)终止后,都无法访问tty.
始终导致的情况SIGHUP包括:
SIGCONT和SIGHUP).在发生这种情况之前,贝壳通常会警告你.huponexit摘要:
$ shopt -s huponexit
$ shopt huponexit
huponexit on
Run Code Online (Sandbox Code Playgroud)
只有交互式 shell 才会在您关闭作业时将其杀死。其他 shell(例如通过使用 获得的 shell su - username)不会这样做。交互式 shell 只会杀死直接子进程。