{
    "content": [
        {
            "type": "text",
            "text": "# PTY(7) (man)\n\n**Summary:** pty - pseudoterminal interfaces\n\n## See Also\n\n- ioctltty(2)\n- select(2)\n- setsid(2)\n- forkpty(3)\n- openpty(3)\n- termios(3)\n- pts(4)\n- tty(4)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **DESCRIPTION** (31 lines) — 2 subsections\n  - UNIX 98 pseudoterminals (14 lines)\n  - BSD pseudoterminals (8 lines)\n- **FILES** (12 lines)\n- **NOTES** (10 lines)\n- **SEE ALSO** (2 lines)\n- **COLOPHON** (7 lines)\n\n## Full Content\n\n### NAME\n\npty - pseudoterminal interfaces\n\n### DESCRIPTION\n\nA  pseudoterminal  (sometimes  abbreviated \"pty\") is a pair of virtual character devices that\nprovide a bidirectional communication channel.  One end of the channel is called the  master;\nthe other end is called the slave.\n\nThe slave end of the pseudoterminal provides an interface that behaves exactly like a classi‐\ncal terminal.  A process that expects to be connected to a terminal, can open the  slave  end\nof a pseudoterminal and then be driven by a program that has opened the master end.  Anything\nthat is written on the master end is provided to the process on the slave end  as  though  it\nwas  input  typed  on a terminal.  For example, writing the interrupt character (usually con‐\ntrol-C) to the master device would cause an interrupt signal (SIGINT) to be generated for the\nforeground  process group that is connected to the slave.  Conversely, anything that is writ‐\nten to the slave end of the pseudoterminal can be read by the process that  is  connected  to\nthe master end.\n\nData  flow  between  master  and  slave is handled asynchronously, much like data flow with a\nphysical terminal.  Data written to the slave will be available at the master  promptly,  but\nmay not be available immediately.  Similarly, there may be a small processing delay between a\nwrite to the master, and the effect being visible at the slave.\n\nHistorically, two pseudoterminal APIs have evolved: BSD and System V.  SUSv1  standardized  a\npseudoterminal API based on the System V API, and this API should be employed in all new pro‐\ngrams that use pseudoterminals.\n\nLinux provides both BSD-style and (standardized) System V-style pseudoterminals.   System  V-\nstyle terminals are commonly called UNIX 98 pseudoterminals on Linux systems.\n\nSince  kernel 2.6.4, BSD-style pseudoterminals are considered deprecated: support can be dis‐\nabled when building the kernel by disabling the CONFIGLEGACYPTYS  option.   (Starting  with\nLinux 2.6.30, that option is disabled by default in the mainline kernel.)  UNIX 98 pseudoter‐\nminals should be used in new applications.\n\n#### UNIX 98 pseudoterminals\n\nAn unused UNIX 98 pseudoterminal master is opened by calling posixopenpt(3).  (This function\nopens the master clone device, /dev/ptmx; see pts(4).)  After performing any program-specific\ninitializations, changing the ownership and permissions of the slave device using grantpt(3),\nand  unlocking  the slave using unlockpt(3)), the corresponding slave device can be opened by\npassing the name returned by ptsname(3) in a call to open(2).\n\nThe Linux kernel imposes a limit on the number of available UNIX 98 pseudoterminals.  In ker‐\nnels  up  to  and  including 2.6.3, this limit is configured at kernel compilation time (CON‐‐\nFIGUNIX98PTYS), and the permitted number of pseudoterminals can be up to 2048, with  a  de‐\nfault  setting  of  256.   Since  kernel  2.6.4,  the  limit  is  dynamically  adjustable via\n/proc/sys/kernel/pty/max, and a corresponding file,  /proc/sys/kernel/pty/nr,  indicates  how\nmany  pseudoterminals  are  currently  in  use.   For further details on these two files, see\nproc(5).\n\n#### BSD pseudoterminals\n\nBSD-style pseudoterminals are provided as precreated pairs, with names of the form /dev/ptyXY\n(master)  and /dev/ttyXY (slave), where X is a letter from the 16-character set [p-za-e], and\nY is a letter from the 16-character set [0-9a-f].  (The precise range of letters in these two\nsets  varies across UNIX implementations.)  For example, /dev/ptyp1 and /dev/ttyp1 constitute\na BSD pseudoterminal pair.  A process finds  an  unused  pseudoterminal  pair  by  trying  to\nopen(2)  each pseudoterminal master until an open succeeds.  The corresponding pseudoterminal\nslave (substitute \"tty\" for \"pty\" in the name of the master) can then be opened.\n\n### FILES\n\n/dev/ptmx\nUNIX 98 master clone device\n\n/dev/pts/*\nUNIX 98 slave devices\n\n/dev/pty[p-za-e][0-9a-f]\nBSD master devices\n\n/dev/tty[p-za-e][0-9a-f]\nBSD slave devices\n\n### NOTES\n\nPseudoterminals are used by applications such as network login services  (ssh(1),  rlogin(1),\ntelnet(1)),  terminal emulators such as xterm(1), script(1), screen(1), tmux(1), unbuffer(1),\nand expect(1).\n\nA description of the TIOCPKT ioctl(2), which controls packet mode operation, can be found  in\nioctltty(2).\n\nThe  BSD ioctl(2) operations TIOCSTOP, TIOCSTART, TIOCUCNTL, and TIOCREMOTE have not been im‐\nplemented under Linux.\n\n### SEE ALSO\n\nioctltty(2), select(2), setsid(2), forkpty(3), openpty(3), termios(3), pts(4), tty(4)\n\n### COLOPHON\n\nThis page is part of release 5.10 of the Linux  man-pages  project.   A  description  of  the\nproject,  information about reporting bugs, and the latest version of this page, can be found\nat https://www.kernel.org/doc/man-pages/.\n\n\n\nLinux                                        2020-08-13                                       PTY(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "PTY",
        "section": "7",
        "mode": "man",
        "summary": "pty - pseudoterminal interfaces",
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "ioctltty",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/ioctltty/2/json"
            },
            {
                "name": "select",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/select/2/json"
            },
            {
                "name": "setsid",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/setsid/2/json"
            },
            {
                "name": "forkpty",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/forkpty/3/json"
            },
            {
                "name": "openpty",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/openpty/3/json"
            },
            {
                "name": "termios",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/termios/3/json"
            },
            {
                "name": "pts",
                "section": "4",
                "url": "https://www.chedong.com/phpMan.php/man/pts/4/json"
            },
            {
                "name": "tty",
                "section": "4",
                "url": "https://www.chedong.com/phpMan.php/man/tty/4/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 31,
                "subsections": [
                    {
                        "name": "UNIX 98 pseudoterminals",
                        "lines": 14
                    },
                    {
                        "name": "BSD pseudoterminals",
                        "lines": 8
                    }
                ]
            },
            {
                "name": "FILES",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COLOPHON",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "pty - pseudoterminal interfaces\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "A  pseudoterminal  (sometimes  abbreviated \"pty\") is a pair of virtual character devices that\nprovide a bidirectional communication channel.  One end of the channel is called the  master;\nthe other end is called the slave.\n\nThe slave end of the pseudoterminal provides an interface that behaves exactly like a classi‐\ncal terminal.  A process that expects to be connected to a terminal, can open the  slave  end\nof a pseudoterminal and then be driven by a program that has opened the master end.  Anything\nthat is written on the master end is provided to the process on the slave end  as  though  it\nwas  input  typed  on a terminal.  For example, writing the interrupt character (usually con‐\ntrol-C) to the master device would cause an interrupt signal (SIGINT) to be generated for the\nforeground  process group that is connected to the slave.  Conversely, anything that is writ‐\nten to the slave end of the pseudoterminal can be read by the process that  is  connected  to\nthe master end.\n\nData  flow  between  master  and  slave is handled asynchronously, much like data flow with a\nphysical terminal.  Data written to the slave will be available at the master  promptly,  but\nmay not be available immediately.  Similarly, there may be a small processing delay between a\nwrite to the master, and the effect being visible at the slave.\n\nHistorically, two pseudoterminal APIs have evolved: BSD and System V.  SUSv1  standardized  a\npseudoterminal API based on the System V API, and this API should be employed in all new pro‐\ngrams that use pseudoterminals.\n\nLinux provides both BSD-style and (standardized) System V-style pseudoterminals.   System  V-\nstyle terminals are commonly called UNIX 98 pseudoterminals on Linux systems.\n\nSince  kernel 2.6.4, BSD-style pseudoterminals are considered deprecated: support can be dis‐\nabled when building the kernel by disabling the CONFIGLEGACYPTYS  option.   (Starting  with\nLinux 2.6.30, that option is disabled by default in the mainline kernel.)  UNIX 98 pseudoter‐\nminals should be used in new applications.\n",
                "subsections": [
                    {
                        "name": "UNIX 98 pseudoterminals",
                        "content": "An unused UNIX 98 pseudoterminal master is opened by calling posixopenpt(3).  (This function\nopens the master clone device, /dev/ptmx; see pts(4).)  After performing any program-specific\ninitializations, changing the ownership and permissions of the slave device using grantpt(3),\nand  unlocking  the slave using unlockpt(3)), the corresponding slave device can be opened by\npassing the name returned by ptsname(3) in a call to open(2).\n\nThe Linux kernel imposes a limit on the number of available UNIX 98 pseudoterminals.  In ker‐\nnels  up  to  and  including 2.6.3, this limit is configured at kernel compilation time (CON‐‐\nFIGUNIX98PTYS), and the permitted number of pseudoterminals can be up to 2048, with  a  de‐\nfault  setting  of  256.   Since  kernel  2.6.4,  the  limit  is  dynamically  adjustable via\n/proc/sys/kernel/pty/max, and a corresponding file,  /proc/sys/kernel/pty/nr,  indicates  how\nmany  pseudoterminals  are  currently  in  use.   For further details on these two files, see\nproc(5).\n"
                    },
                    {
                        "name": "BSD pseudoterminals",
                        "content": "BSD-style pseudoterminals are provided as precreated pairs, with names of the form /dev/ptyXY\n(master)  and /dev/ttyXY (slave), where X is a letter from the 16-character set [p-za-e], and\nY is a letter from the 16-character set [0-9a-f].  (The precise range of letters in these two\nsets  varies across UNIX implementations.)  For example, /dev/ptyp1 and /dev/ttyp1 constitute\na BSD pseudoterminal pair.  A process finds  an  unused  pseudoterminal  pair  by  trying  to\nopen(2)  each pseudoterminal master until an open succeeds.  The corresponding pseudoterminal\nslave (substitute \"tty\" for \"pty\" in the name of the master) can then be opened.\n"
                    }
                ]
            },
            "FILES": {
                "content": "/dev/ptmx\nUNIX 98 master clone device\n\n/dev/pts/*\nUNIX 98 slave devices\n\n/dev/pty[p-za-e][0-9a-f]\nBSD master devices\n\n/dev/tty[p-za-e][0-9a-f]\nBSD slave devices\n",
                "subsections": []
            },
            "NOTES": {
                "content": "Pseudoterminals are used by applications such as network login services  (ssh(1),  rlogin(1),\ntelnet(1)),  terminal emulators such as xterm(1), script(1), screen(1), tmux(1), unbuffer(1),\nand expect(1).\n\nA description of the TIOCPKT ioctl(2), which controls packet mode operation, can be found  in\nioctltty(2).\n\nThe  BSD ioctl(2) operations TIOCSTOP, TIOCSTART, TIOCUCNTL, and TIOCREMOTE have not been im‐\nplemented under Linux.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "ioctltty(2), select(2), setsid(2), forkpty(3), openpty(3), termios(3), pts(4), tty(4)\n",
                "subsections": []
            },
            "COLOPHON": {
                "content": "This page is part of release 5.10 of the Linux  man-pages  project.   A  description  of  the\nproject,  information about reporting bugs, and the latest version of this page, can be found\nat https://www.kernel.org/doc/man-pages/.\n\n\n\nLinux                                        2020-08-13                                       PTY(7)",
                "subsections": []
            }
        }
    }
}