为什么在否认进程后我仍然收到 stdout 或 stderr?

为什么在否认进程后我仍然收到 stdout 或 stderr?

我启动了 QEMU 并立即否认了它,但仍然在我的 shell 上收到输出:

aburk@aburk:~$ su
Password: 
[root@aburk aburk]# QEMU_AUDIO_DRV="pa" QEMU_PA_SERVER="/run/user/1000/pulse/native" qemu-system-x86_64 -m 3096M -hda /dev/sdb -cpu host -smp cores=3,threads=1,sockets=1 --enable-kvm
WARNING: Image format was not specified for '/dev/sdb' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
^Z
[1]+  Stopped                 QEMU_AUDIO_DRV="pa" QEMU_PA_SERVER="/run/user/1000/pulse/native" qemu-system-x86_64 -m 3096M -hda /dev/sdb -cpu host -smp cores=3,threads=1,sockets=1 --enable-kvm
[root@aburk aburk]# bg
[1]+ QEMU_AUDIO_DRV="pa" QEMU_PA_SERVER="/run/user/1000/pulse/native" qemu-system-x86_64 -m 3096M -hda /dev/sdb -cpu host -smp cores=3,threads=1,sockets=1 --enable-kvm &
[root@aburk aburk]# 
(qemu-system-x86_64:19530): Gtk-WARNING **: Allocating size to GtkScrollbar 0x7f261f20c2c0 without calling gtk_widget_get_preferred_width/height(). How does the code know the size to allocate?

(qemu-system-x86_64:19530): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -150829368 and height 400

(qemu-system-x86_64:19530): Gtk-WARNING **: Allocating size to GtkScrollbar 0x7f261f20c4c0 without calling gtk_widget_get_preferred_width/height(). How does the code know the size to allocate?

(qemu-system-x86_64:19530): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -150829368 and height 400

(qemu-system-x86_64:19530): Gtk-WARNING **: Allocating size to GtkScrollbar 0x7f261f20c6c0 without calling gtk_widget_get_preferred_width/height(). How does the code know the size to allocate?

(qemu-system-x86_64:19530): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -150829368 and height 400
jobs -p
19530
[root@aburk aburk]# disown 19530
[root@aburk aburk]# 
[root@aburk aburk]# 
[root@aburk aburk]# 
(qemu-system-x86_64:19530): Gtk-WARNING **: Allocating size to GtkScrollbar 0x7f261f20c2c0 without calling gtk_widget_get_preferred_width/height(). How does the code know the size to allocate?

(qemu-system-x86_64:19530): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -150829368 and height 900

(qemu-system-x86_64:19530): Gtk-WARNING **: Allocating size to GtkScrollbar 0x7f261f20c4c0 without calling gtk_widget_get_preferred_width/height(). How does the code know the size to allocate?

(qemu-system-x86_64:19530): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -150829368 and height 900

(qemu-system-x86_64:19530): Gtk-WARNING **: Allocating size to GtkScrollbar 0x7f261f20c6c0 without calling gtk_widget_get_preferred_width/height(). How does the code know the size to allocate?

(qemu-system-x86_64:19530): Gtk-WARNING **: gtk_widget_size_allocate(): attempt to allocate widget with width -150829368 and height 900

我可以通过从“视图”菜单中调整 QEMU 的大小来手动触发 GTK 警告。

我没有正确地否认这个过程吗?为什么我仍然收到输出?

我注意到,当我完全关闭 shell 并打开一个新 shell 并 su 到 root 时,无论我多久调整 QEMU 大小,我都不会收到任何这些消息。

我想知道这是如何运作的。

答案1

disown仅从活动作业表(由 shell 维护)中删除作业,确保 shell 终止时相应的进程不会被终止。它不会改变进程的 I/O 设置(标准输入、输出和错误);因此,被拒绝的作业的输出仍然会发送到它启动的终端,或者重定向到它被重定向的任何地方。如果关闭终端(假设输出正在那里),则输出将丢失,并且打开新的 shell 将无法恢复输出。在这种情况下,一旦进程尝试从终端读取或写入,它就会收到挂断信号;看nohup、disown 和 & 之间的区别了解详情。

为了完全避免该问题,您可以将进程的输出重定向到/dev/null启动时的输出。

相关内容