1OPENPTY(3)                 Linux Programmer's Manual                OPENPTY(3)
2
3
4

NAME

6       openpty, login_tty, forkpty - tty utility functions
7

SYNOPSIS

9       #include <pty.h>  /* for openpty and forkpty */
10       #include <utmp.h> /* for login_tty */
11
12       int  openpty(int  *amaster,  int  *aslave,  char  *name, struct termios
13       *termp, struct winsize * winp);
14
15       int login_tty(int fd);
16
17       pid_t forkpty(int *amaster, char *name, struct termios  *termp,  struct
18       winsize *winp);
19
20       Link with -lutil.
21

DESCRIPTION

23       The  openpty()  function finds an available pseudo-terminal and returns
24       file descriptors for the master and slave in amaster  and  aslave.   If
25       name  is  not  NULL, the filename of the slave is returned in name.  If
26       termp is not NULL, the terminal parameters of the slave will be set  to
27       the values in termp.  If winp is not NULL, the window size of the slave
28       will be set to the values in winp.
29
30       The login_tty() function prepares for a login on the tty fd (which  may
31       be  a real tty device, or the slave of a pseudo-terminal as returned by
32       openpty()) by creating a new session, making fd the controlling  termi‐
33       nal  for the current process, setting fd to be the standard input, out‐
34       put, and error streams of the current process, and closing fd.
35
36       The forkpty() function combines openpty(), fork(), and  login_tty()  to
37       create a new process operating in a pseudo-terminal.  The file descrip‐
38       tor of the master side of the pseudo-terminal is returned  in  amaster,
39       and the filename of the slave in name if it is not NULL.  The termp and
40       winp parameters, if not NULL, will determine  the  terminal  attributes
41       and window size of the slave side of the pseudo-terminal.
42

RETURN VALUES

44       If a call to openpty(), login_tty(), or forkpty() is not successful, -1
45       is returned and  errno  is  set  to  indicate  the  error.   Otherwise,
46       openpty(),  login_tty(),  and  the child process of forkpty() return 0,
47       and the parent process of forkpty() returns the process ID of the child
48       process.
49

ERRORS

51       openpty() will fail if:
52
53       ENOENT There are no available ttys.
54
55       login_pty()  will  fail  if  ioctl() fails to set fd to the controlling
56       terminal of the current process.
57
58       forkpty() will fail if either openpty() or fork() fails.
59

NOTES

61       These functions are included in  libutil,  hence  you'll  need  to  add
62       -lutil to your compiler command line.
63
64       In  versions of glibc before 2.0.92, openpty() returns file descriptors
65       for a BSD pseudo-terminal pair; since glibc 2.0.92, it  first  attempts
66       to open a Unix 98 pseudo-terminal pair, and falls back to opening a BSD
67       pseudo-terminal pair if that fails.
68

CONFORMING TO

70       These are BSD functions, present in libc5 and glibc2.
71

BUGS

73       Nobody knows how much space should be reserved for name.   So,  calling
74       openpty() or forkpty() with non-NULL name may not be secure.
75

SEE ALSO

77       fork(2), pty(7)
78
79
80
81BSD                               2003-07-18                        OPENPTY(3)
Impressum