256和512的响应码是什么操作系统在python脚本中

2024-10-02 22:36:19 发布

您现在位置:Python中文网/ 问答频道 /正文

当我ping服务器时操作系统在python中,我得到多个响应代码。 使用的命令-os.system("ping -q -c 30 -s SERVERANME")

  • 0-联机
  • 256-离线
  • 512-512是什么意思?在

Tags: 代码命令os联机pingsystem离线服务器时
1条回答
网友
1楼 · 发布于 2024-10-02 22:36:19

根据the docs

On Unix, the return value is the exit status of the process encoded in the format specified for wait(). Note that POSIX does not specify the meaning of the return value of the C system() function, so the return value of the Python function is system-dependent.

the ^{} docs say

Wait for completion of a child process, and return a tuple containing its pid and exit status indication: a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero); the high bit of the low byte is set if a core file was produced.

因此0、256和512对应于ping正常退出(不被信号杀死),退出状态为0 == 0 << 80传统上表示“成功”)、256 == 1 << 81通常表示“正常”失败)和512 == 2 << 8(不一致,但{}常用来表示参数解析失败)。在本例中,您传递了-s,但没有提供开关所需的强制值(packetsize),因此退出状态2是有意义的。在

相关问题 更多 >