1OPENPTY(3) Linux Programmer's Manual OPENPTY(3)
2
3
4
6 openpty, login_tty, forkpty - terminal 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 pseudoterminal 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 terminal fd (which
34 may be a real terminal device, or the slave of a pseudoterminal as
35 returned by openpty()) by creating a new session, making fd the con‐
36 trolling terminal for the calling process, setting fd to be the stan‐
37 dard input, output, and error streams of the current process, and clos‐
38 ing fd.
39
40 The forkpty() function combines openpty(), fork(2), and login_tty() to
41 create a new process operating in a pseudoterminal. The file descrip‐
42 tor of the master side of the pseudoterminal is returned in amaster,
43 and the filename of the slave in name if it is not NULL. The termp and
44 winp arguments, if not NULL, will determine the terminal attributes and
45 window size of the slave side of the pseudoterminal.
46
48 If a call to openpty(), login_tty(), or forkpty() is not successful, -1
49 is returned and errno is set to indicate the error. Otherwise,
50 openpty(), login_tty(), and the child process of forkpty() return 0,
51 and the parent process of forkpty() returns the process ID of the child
52 process.
53
55 openpty() will fail if:
56
57 ENOENT There are no available terminals.
58
59 login_tty() will fail if ioctl(2) fails to set fd to the controlling
60 terminal of the calling process.
61
62 forkpty() will fail if either openpty() or fork(2) fails.
63
65 These are BSD functions, present in libc5 and glibc2. They are not
66 standardized in POSIX.
67
69 The const modifiers were added to the structure pointer arguments of
70 openpty() and forkpty() in glibc 2.8.
71
72 In versions of glibc before 2.0.92, openpty() returns file descriptors
73 for a BSD pseudoterminal pair; since glibc 2.0.92, it first attempts to
74 open a UNIX 98 pseudoterminal pair, and falls back to opening a BSD
75 pseudoterminal pair if that fails.
76
78 Nobody knows how much space should be reserved for name. So, calling
79 openpty() or forkpty() with non-NULL name may not be secure.
80
82 fork(2), ttyname(3), pty(7)
83
85 This page is part of release 3.53 of the Linux man-pages project. A
86 description of the project, and information about reporting bugs, can
87 be found at http://www.kernel.org/doc/man-pages/.
88
89
90
91GNU 2010-06-13 OPENPTY(3)