{
    "mode": "pydoc",
    "parameter": "fcntl",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/fcntl/json",
    "generated": "2026-06-02T13:24:47Z",
    "sections": {
        "NAME": {
            "content": "fcntl\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module performs file control and I/O control on file\ndescriptors.  It is an interface to the fcntl() and ioctl() Unix\nroutines.  File descriptors can be obtained with the fileno() method of\na file or socket object.\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "fcntl",
                    "content": "Perform the operation `cmd` on file descriptor fd.\n\nThe values used for `cmd` are operating system dependent, and are available\nas constants in the fcntl module, using the same names as used in\nthe relevant C header files.  The argument arg is optional, and\ndefaults to 0; it may be an int or a string.  If arg is given as a string,\nthe return value of fcntl is a string of that length, containing the\nresulting value put in the arg buffer by the operating system.  The length\nof the arg string is not allowed to exceed 1024 bytes.  If the arg given\nis an integer or if none is specified, the result value is an integer\ncorresponding to the return value of the fcntl call in the C code.\n"
                },
                {
                    "name": "flock",
                    "content": "Perform the lock operation `operation` on file descriptor `fd`.\n\nSee the Unix manual page for flock(2) for details (On some systems, this\nfunction is emulated using fcntl()).\n"
                },
                {
                    "name": "ioctl",
                    "content": "Perform the operation `request` on file descriptor `fd`.\n\nThe values used for `request` are operating system dependent, and are available\nas constants in the fcntl or termios library modules, using the same names as\nused in the relevant C header files.\n\nThe argument `arg` is optional, and defaults to 0; it may be an int or a\nbuffer containing character data (most likely a string or an array).\n\nIf the argument is a mutable buffer (such as an array) and if the\nmutateflag argument (which is only allowed in this case) is true then the\nbuffer is (in effect) passed to the operating system and changes made by\nthe OS will be reflected in the contents of the buffer after the call has\nreturned.  The return value is the integer returned by the ioctl system\ncall.\n\nIf the argument is a mutable buffer and the mutableflag argument is false,\nthe behavior is as if a string had been passed.\n\nIf the argument is an immutable buffer (most likely a string) then a copy\nof the buffer is passed to the operating system and the return value is a\nstring of the same length containing whatever the operating system put in\nthe buffer.  The length of the arg buffer in this case is not allowed to\nexceed 1024 bytes.\n\nIf the arg given is an integer or if none is specified, the result value is\nan integer corresponding to the return value of the ioctl call in the C\ncode.\n"
                },
                {
                    "name": "lockf",
                    "content": "A wrapper around the fcntl() locking calls.\n\n`fd` is the file descriptor of the file to lock or unlock, and operation is one\nof the following values:\n\nLOCKUN - unlock\nLOCKSH - acquire a shared lock\nLOCKEX - acquire an exclusive lock\n\nWhen operation is LOCKSH or LOCKEX, it can also be bitwise ORed with\nLOCKNB to avoid blocking on lock acquisition.  If LOCKNB is used and the\nlock cannot be acquired, an OSError will be raised and the exception will\nhave an errno attribute set to EACCES or EAGAIN (depending on the operating\nsystem -- for portability, check for either value).\n\n`len` is the number of bytes to lock, with the default meaning to lock to\nEOF.  `start` is the byte offset, relative to `whence`, to that the lock\nstarts.  `whence` is as with fileobj.seek(), specifically:\n\n0 - relative to the start of the file (SEEKSET)\n1 - relative to the current buffer position (SEEKCUR)\n2 - relative to the end of the file (SEEKEND)\n"
                }
            ]
        },
        "DATA": {
            "content": "DNACCESS = 1\nDNATTRIB = 32\nDNCREATE = 4\nDNDELETE = 8\nDNMODIFY = 2\nDNMULTISHOT = 2147483648\nDNRENAME = 16\nFASYNC = 8192\nFDCLOEXEC = 1\nFADDSEALS = 1033\nFDUPFD = 0\nFDUPFDCLOEXEC = 1030\nFEXLCK = 4\nFGETFD = 1\nFGETFL = 3\nFGETLEASE = 1025\nFGETLK = 5\nFGETLK64 = 5\nFGETOWN = 9\nFGETPIPESZ = 1032\nFGETSIG = 11\nFGETSEALS = 1034\nFNOTIFY = 1026\nFOFDGETLK = 36\nFOFDSETLK = 37\nFOFDSETLKW = 38\nFRDLCK = 0\nFSEALGROW = 4\nFSEALSEAL = 1\nFSEALSHRINK = 2\nFSEALWRITE = 8\nFSETFD = 2\nFSETFL = 4\nFSETLEASE = 1024\nFSETLK = 6\nFSETLK64 = 6\nFSETLKW = 7\nFSETLKW64 = 7\nFSETOWN = 8\nFSETPIPESZ = 1031\nFSETSIG = 10\nFSHLCK = 8\nFUNLCK = 2\nFWRLCK = 1\nLOCKEX = 2\nLOCKMAND = 32\nLOCKNB = 4\nLOCKREAD = 64\nLOCKRW = 192\nLOCKSH = 1\nLOCKUN = 8\nLOCKWRITE = 128\n",
            "subsections": []
        },
        "FILE": {
            "content": "(built-in)\n\n",
            "subsections": []
        }
    },
    "summary": "fcntl",
    "flags": [],
    "examples": [],
    "see_also": []
}