1OPENPTY(3) Linux Programmer's Manual OPENPTY(3)
2
3
4
6 openpty, login_tty, forkpty - tty utility functions
7
9 #include <pty.h>
10
11 int openpty(int *amaster, int *aslave, char *name,
12 const struct termios *termp,
13 const struct winsize *winp);
14
15 pid_t forkpty(int *amaster, char *name,
16 const struct termios *termp,
17 const struct winsize *winp);
18
19 #include <utmp.h>
20
21 int login_tty(int fd);
22
23 Link with -lutil.
24
26 The openpty() function finds an available pseudo-terminal and returns
27 file descriptors for the master and slave in amaster and aslave. If
28 name is not NULL, the filename of the slave is returned in name. If
29 termp is not NULL, the terminal parameters of the slave will be set to
30 the values in termp. If winp is not NULL, the window size of the slave
31 will be set to the values in winp.
32
33 The login_tty() function prepares for a login on the tty fd (which may
34 be a real tty device, or the slave of a pseudo-terminal as returned by
35 openpty()) by creating a new session, making fd the controlling termi‐
36 nal for the calling process, setting fd to be the standard input, out‐
37 put, and error streams of the current process, and closing fd.
38
39 The forkpty() function combines openpty(), fork(2), and login_tty() to
40 create a new process operating in a pseudo-terminal. The file descrip‐
41 tor of the master side of the pseudo-terminal is returned in amaster,
42 and the filename of the slave in name if it is not NULL. The termp and
43 winp arguments, if not NULL, will determine the terminal attributes and
44 window size of the slave side of the pseudo-terminal.
45
47 If a call to openpty(), login_tty(), or forkpty() is not successful, -1
48 is returned and errno is set to indicate the error. Otherwise,
49 openpty(), login_tty(), and the child process of forkpty() return 0,
50 and the parent process of forkpty() returns the process ID of the child
51 process.
52
54 openpty() will fail if:
55
56 ENOENT There are no available ttys.
57
58 login_tty() will fail if ioctl(2) fails to set fd to the controlling
59 terminal of the calling process.
60
61 forkpty() will fail if either openpty() or fork(2) fails.
62
64 These are BSD functions, present in libc5 and glibc2. They are not
65 standardized in POSIX.
66
68 The const modifiers were added to the structure pointer arguments of
69 openpty() and forkpty() in glibc 2.8.
70
71 In versions of glibc before 2.0.92, openpty() returns file descriptors
72 for a BSD pseudo-terminal pair; since glibc 2.0.92, it first attempts
73 to open a Unix 98 pseudo-terminal pair, and falls back to opening a BSD
74 pseudo-terminal pair if that fails.
75
77 Nobody knows how much space should be reserved for name. So, calling
78 openpty() or forkpty() with non-NULL name may not be secure.
79
81 fork(2), ttyname(3), pty(7)
82
84 This page is part of release 3.25 of the Linux man-pages project. A
85 description of the project, and information about reporting bugs, can
86 be found at http://www.kernel.org/doc/man-pages/.
87
88
89
90GNU 2010-06-13 OPENPTY(3)