Skip to content

Instantly share code, notes, and snippets.

@dcoles
Created September 22, 2016 03:54
Show Gist options
  • Save dcoles/4b2f347f11fcf88b5f4b446f6d0d67af to your computer and use it in GitHub Desktop.
Save dcoles/4b2f347f11fcf88b5f4b446f6d0d67af to your computer and use it in GitHub Desktop.
# Print the number of bytes unread in a fifo.
# David Coles <[email protected]>
import argparse
import ctypes
import fcntl
import os
import sys
import termios
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("path")
args = parser.parse_args()
fd = os.open(args.path, os.O_RDONLY|os.O_NONBLOCK)
size = ctypes.c_int(0)
fcntl.ioctl(fd, termios.FIONREAD, size, True)
print(size.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment