Linux命令中Ctrl+z、Ctrl+c和Ctrl+d的區別和使用
Ctrl+c,Ctrl+d,Ctrl+z在Linux中意義
Ctrl+c和ctrl+z都是中斷命令,但是他們的作用卻不一樣.
Ctrl+c是強制中斷程序的執行。
Ctrl+z的是將任務中斷,但是此任務並沒有結束,他仍然在進程中他只是維持掛起的狀態。
[root@localhost ~]# ping baidu.com
PING baidu.com (220.181.57.217) 56(84) bytes of data.
64 bytes from 220.181.57.217: icmp_seq=1 ttl=128 time=58.7 ms
64 bytes from 220.181.57.217: icmp_seq=2 ttl=128 time=76.6 ms
64 bytes from 220.181.57.217: icmp_seq=3 ttl=128 time=54.6 ms
64 bytes from 220.181.57.217: icmp_seq=4 ttl=128 time=72.7 ms
64 bytes from 220.181.57.217: icmp_seq=5 ttl=128 time=51.3 ms
64 bytes from 220.181.57.217: icmp_seq=6 ttl=128 time=124 ms
64 bytes from 220.181.57.217: icmp_seq=7 ttl=128 time=71.2 ms
64 bytes from 220.181.57.217: icmp_seq=8 ttl=128 time=52.4 ms
64 bytes from 220.181.57.217: icmp_seq=9 ttl=128 time=51.7 ms
64 bytes from 220.181.57.217: icmp_seq=10 ttl=128 time=254 ms
64 bytes from 220.181.57.217: icmp_seq=12 ttl=128 time=64.2 ms
64 bytes from 220.181.57.217: icmp_seq=13 ttl=128 time=51.8 ms
64 bytes from 220.181.57.217: icmp_seq=14 ttl=128 time=92.5 ms
64 bytes from 220.181.57.217: icmp_seq=15 ttl=128 time=52.1 ms
64 bytes from 220.181.57.217: icmp_seq=16 ttl=128 time=51.8 ms
^Z
[1]+ Stopped ping baidu.com
12345678910111213141516171819
用戶可以使用fg/bg操作繼續前臺或後臺的任務,
fg命令重新啓動前臺被中斷的任務,
[root@localhost ~]# fg
ping baidu.com
64 bytes from 180.149.132.47: icmp_seq=6 ttl=128 time=59.0 ms
64 bytes from 180.149.132.47: icmp_seq=7 ttl=128 time=67.2 ms
64 bytes from 180.149.132.47: icmp_seq=8 ttl=128 time=54.5 ms
64 bytes from 180.149.132.47: icmp_seq=10 ttl=128 time=55.9 ms
64 bytes from 180.149.132.47: icmp_seq=12 ttl=128 time=56.8 ms
64 bytes from 180.149.132.47: icmp_seq=13 ttl=128 time=60.0 ms
64 bytes from 180.149.132.47: icmp_seq=14 ttl=128 time=155 ms
^Z
[1]+ Stopped ping baidu.com
1234567891011
bg命令把被中斷的任務放在後臺執行.
例如:當你vi一個文件是,如果需要用shell執行別的操作,但是你又不打算關閉vi,因爲你得存盤推出,你可以簡單的按下Ctrl+z,shell會將vi進程掛起~,當你結束了那個shell操作之後,你可以用fg命令繼續vi你的文件。
Ctrl+d 不是發送信號,而是表示一個特殊的二進制值,表示 EOF。