Io-Redirection
為什麼我在取消程序後仍會收到 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
我可以通過在 View 菜單中調整 QEMU 的大小來手動觸發 GTK 警告。
我沒有正確地否認這個過程嗎?為什麼我仍然收到輸出?
我注意到,當我完全關閉我的 shell 並打開一個新的 shell 並 su 到 root 時,無論我多久調整一次 QEMU 的大小,我都不會收到任何這些消息。
我想知道這是如何工作的。
disown
只從活動作業表中刪除一個作業(由 shell 維護),確保當 shell 終止時相應的程序不會被殺死。它不會改變程序的 I/O 設置(標準輸入、輸出和錯誤);因此,disowned 作業的輸出仍然會發送到它開始的終端,或者它被重定向的任何地方。如果您關閉終端(假設輸出正在那裡),那麼輸出將失去,並且打開一個新的 shell 不會恢復輸出。在這種情況下,只要程序嘗試讀取或寫入終端,就會收到掛斷信號;有關詳細資訊,請參閱nohup、disown 和 & 之間的區別。為了完全避免這個問題,您可以將程序的輸出重定向到
/dev/null
啟動它的時間。