5

When i ping servers with os.system in python i get multiple response codes. Command used - os.system("ping -q -c 30 -s SERVERANME")

  • 0 - Online
  • 256 - Offline
  • 512 - what does 512 mean ?
ShadowRanger
  • 124,179
  • 11
  • 158
  • 228
DevUser
  • 89
  • 2
  • 5
  • The `-s` option of `ping` is used to set a packet size, but you have not specified one. You should either eliminate the `-s` or add a `packetsize`. – John Anderson Mar 06 '19 at 01:55

1 Answers1

7

Per 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.

And the wait 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.

So 0, 256 and 512 correspond to ping exiting normally (not killed by signal) with exit statuses of 0 == 0 << 8 (0 traditionally means "success"), 256 == 1 << 8 (1 typically means "normal" failure) and 512 == 2 << 8 (not consistent, but 2 is frequently used to indicate an argument parsing failure). In this case, you passed -s without providing the mandatory value (packetsize) that switch requires, so an exit status of 2 makes sense.

ShadowRanger
  • 124,179
  • 11
  • 158
  • 228