Created
July 20, 2013 09:17
-
-
Save atdt/6044411 to your computer and use it in GitHub Desktop.
Get maximum pipe size. See F_GETPIPE_SZ in fcntl(2).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Get maximum pipe size (F_GETPIPE_SZ) | |
See http://man7.org/linux/man-pages/man2/fcntl.2.html | |
""" | |
import fcntl | |
import os | |
F_GETPIPE_SZ = 1032 # Linux 2.6.35+ | |
def get_max_pipe(): | |
"""Get the maximum pipe buffer size or None.""" | |
r, w = os.pipe() | |
try: | |
return fcntl.fcntl(w, F_GETPIPE_SZ) | |
except OSError: | |
return None | |
finally: | |
os.closerange(r, w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this. The return value of the call to fcntl represents the capacity of the pipe, not the maximum size.
The maximum size can be learned by reading
/proc/sys/fs/pipe-max-size
from http://man7.org/linux/man-pages/man2/fcntl.2.html