2ma*_*mac 39 linux command-line gnu ping
有没有办法在ping不停止执行的情况下告诉显示其通常的终止统计信息?
例如,我想快速查看:
--- 8.8.8.8 ping statistics ---
2410 packets transmitted, 2274 received, +27 errors, 5% packet loss, time 2412839ms
rtt min/avg/max/mdev = 26.103/48.917/639.493/52.093 ms, pipe 3
Run Code Online (Sandbox Code Playgroud)
无需停止程序,从而丢失累积的数据。
smh*_*ich 38
从ping联机帮助页(强调我的):
当已发送(和接收)指定数量的数据包或程序以 SIGINT 终止时,将显示简短摘要。无需通过信号 SIGQUIT 终止进程即可获得更短的当前统计信息。
因此,如果您的统计数据稍微不那么冗长,这将起作用:
# the second part is only for showing you the PID
ping 8.8.8.8 & jobs ; fg
<... in another terminal ...>
kill -SIGQUIT $PID
Run Code Online (Sandbox Code Playgroud)
简短的统计数据如下所示:
19/19 packets, 0% loss, min/avg/ewma/max = 0.068/0.073/0.074/0.088 ms
Run Code Online (Sandbox Code Playgroud)
小智 20
还有一种更简单的方法可以在执行期间获取 ping 统计信息:只需按Ctrl + | (垂直斜线或也称为管道线)
我个人确实经常使用它,试试看:
64 bytes from 192.168.1.1: icmp_seq=6 ttl=64 time=0.893 ms
64 bytes from 192.168.1.1: icmp_seq=23 ttl=64 time=0.862 ms
64 bytes from 192.168.1.1: icmp_seq=24 ttl=64 time=3.18 ms
64 bytes from 192.168.1.1: icmp_seq=35 ttl=64 time=0.877 ms
64 bytes from 192.168.1.1: icmp_seq=36 ttl=64 time=0.866 ms
**36/36 packets, 0% loss, min/avg/ewma/max = 0.832/0.993/0.930/3.185 ms**
64 bytes from 192.168.1.1: icmp_seq=37 ttl=64 time=0.909 ms
64 bytes from 192.168.1.1: icmp_seq=38 ttl=64 time=2.03 ms
64 bytes from 192.168.1.1: icmp_seq=39 ttl=64 time=0.839 ms
64 bytes from 192.168.1.1: icmp_seq=40 ttl=64 time=0.880 ms
Run Code Online (Sandbox Code Playgroud)
Sta*_*ild 10
发送SIGQUIT信号。
输出示例:
64 bytes from localhost (127.0.0.1): icmp_seq=138 ttl=64 time=0.021 ms
64 bytes from localhost (127.0.0.1): icmp_seq=139 ttl=64 time=0.022 ms
139/139 packets, 0% loss, min/avg/ewma/max = 0.014/0.022/0.022/0.057 ms
64 bytes from localhost (127.0.0.1): icmp_seq=140 ttl=64 time=0.090 ms
64 bytes from localhost (127.0.0.1): icmp_seq=141 ttl=64 time=0.025 ms
Run Code Online (Sandbox Code Playgroud)
CTRL+ \=quit根据stty -a.
这些也有效:CTRL+ |; CTRL+ 4;
64 bytes from localhost (127.0.0.1): icmp_seq=138 ttl=64 time=0.021 ms
64 bytes from localhost (127.0.0.1): icmp_seq=139 ttl=64 time=0.022 ms
139/139 packets, 0% loss, min/avg/ewma/max = 0.014/0.022/0.022/0.057 ms
64 bytes from localhost (127.0.0.1): icmp_seq=140 ttl=64 time=0.090 ms
64 bytes from localhost (127.0.0.1): icmp_seq=141 ttl=64 time=0.025 ms
Run Code Online (Sandbox Code Playgroud)
kill -SIGQUIT <pid> [...]
Run Code Online (Sandbox Code Playgroud)
ps -o pid= -C ping | xargs -r kill -SIGQUIT
Run Code Online (Sandbox Code Playgroud)
while sleep 20; do ps -o pid= -C ping | xargs -r kill -SIGQUIT; done
Run Code Online (Sandbox Code Playgroud)
发送INFO信号。
CTRL通过+发送时的示例输出T:
64 bytes from 127.0.0.1: icmp_seq=137 ttl=64 time=0.328 ms
64 bytes from 127.0.0.1: icmp_seq=138 ttl=64 time=0.028 ms
load: 0.18 cmd: ping 62483 [select] 144.69r 0.00u 0.01s 0% 2256k
139/139 packets received (100.0%) 0.018 min / 0.072 avg / 0.505 max
64 bytes from 127.0.0.1: icmp_seq=139 ttl=64 time=0.116 ms
64 bytes from 127.0.0.1: icmp_seq=140 ttl=64 time=0.027 ms
Run Code Online (Sandbox Code Playgroud)
通过以下方式发送时的示例输出kill:
64 bytes from 127.0.0.1: icmp_seq=137 ttl=64 time=0.328 ms
64 bytes from 127.0.0.1: icmp_seq=138 ttl=64 time=0.028 ms
139/139 packets received (100.0%) 0.018 min / 0.072 avg / 0.505 max
64 bytes from 127.0.0.1: icmp_seq=139 ttl=64 time=0.116 ms
64 bytes from 127.0.0.1: icmp_seq=140 ttl=64 time=0.027 ms
Run Code Online (Sandbox Code Playgroud)
CTRL+ T=status根据stty -a.
while sleep 20; do ps -o pid= -C ping | xargs -r kill -SIGQUIT; done &
Run Code Online (Sandbox Code Playgroud)
64 bytes from 127.0.0.1: icmp_seq=137 ttl=64 time=0.328 ms
64 bytes from 127.0.0.1: icmp_seq=138 ttl=64 time=0.028 ms
load: 0.18 cmd: ping 62483 [select] 144.69r 0.00u 0.01s 0% 2256k
139/139 packets received (100.0%) 0.018 min / 0.072 avg / 0.505 max
64 bytes from 127.0.0.1: icmp_seq=139 ttl=64 time=0.116 ms
64 bytes from 127.0.0.1: icmp_seq=140 ttl=64 time=0.027 ms
Run Code Online (Sandbox Code Playgroud)
64 bytes from 127.0.0.1: icmp_seq=137 ttl=64 time=0.328 ms
64 bytes from 127.0.0.1: icmp_seq=138 ttl=64 time=0.028 ms
139/139 packets received (100.0%) 0.018 min / 0.072 avg / 0.505 max
64 bytes from 127.0.0.1: icmp_seq=139 ttl=64 time=0.116 ms
64 bytes from 127.0.0.1: icmp_seq=140 ttl=64 time=0.027 ms
Run Code Online (Sandbox Code Playgroud)
kill -INFO <pid> [...]
Run Code Online (Sandbox Code Playgroud)
感谢@pmos 的回答,它首先为我播下了周期性方法的想法,并感谢所有其他对此做出贡献的答案和评论。
感谢@VictorYarema提出将我的评论转化为实际答案的建议。原始评论中的方法的本质是相同的,但随着时间的推移已经演变如下:
-r选项以xargs防止kill在没有结果时在没有 pid 的情况下运行psps我使用了-o pid=将列标题文本设置为空的选项,而不是h因为h对于 Linux 和 FreeBSD 有不同的含义
ps支持显式--no-headers选项,但 FreeBSD 则不然sleep命令移至while测试条件awk小智 6
试试Ctrl+4
它显示了这样的一行:
312/312 packets, 0% loss, min/avg/ewma/max = 0.312/1.236/0.505/208.655 ms
Run Code Online (Sandbox Code Playgroud)