bg 命令的实际用途是什么?

Lan*_*nes 1 job-control

这是输出:

[USER@SERVER ~] ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.037 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.030 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.026 ms
^Z
[1]+  Stopped                 ping localhost
[USER@SERVER ~] jobs
[1]+  Stopped                 ping localhost
[USER@SERVER ~] bg %1
[1]+ ping localhost &
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.034 ms
[USER@SERVER ~] 64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.030 ms
64 bytes from localhost (127.0.0.1): icmp_seq=8 ttl=64 time=0.032 ms

[USER@SERVER ~] ^C
[USER@SERVER ~] ^C
[USER@SERVER ~] 64 bytes from localhost (127.0.0.1): icmp_seq=9 ttl=64 time=0.031 ms
^C
[USER@SERVER ~] 64 bytes from localhost (127.0.0.1): icmp_seq=10 ttl=64 time=0.031 ms
64 bytes from localhost (127.0.0.1): icmp_seq=11 ttl=64 time=0.028 ms
ki64 bytes from localhost (127.0.0.1): icmp_seq=12 ttl=64 time=0.030 ms
ll %64 bytes from localhost (127.0.0.1): icmp_seq=13 ttl=64 time=0.031 ms
1
[1]+  Terminated              ping localhost
[USER@SERVER ~] 
Run Code Online (Sandbox Code Playgroud)

of:

1) 我开始 ping localhost
2) CTRL+Z
3) bg %1
4) CTRL+C 不起作用。
5)我必须输入“kill %1”才能杀死它。


“bg”命令的实际用途是什么?它在现实世界中在哪里使用?

jof*_*fel 13

bg通常用于在后台运行程序,它没有控制台交互,就像大多数具有图形用户界面的程序一样。

示例:您想运行xterm &但忘记&在后台运行终端模拟器。所以你用 停止(阻塞)前台 xterm 进程Ctrl-Z并在后台继续它bg

如果要发送Ctrl-C到后台进程,请fg再次将其放在前台(或使用kill -2 %1)。