The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
pty.h File Reference

open a pseudo-terminal pair, and make one a process's terminal. More...

#include <sys/ioctl.h>
#include <termios.h>

Go to the source code of this file.

Functions

int openpty (int *master, int *slave, char *name, const struct termios *settings, const struct winsize *size)
 open a new pseudo-terminal pair.
int login_tty (int fd)
 make fd the terminal of the calling process: start a new session, make fd its controlling terminal, put fd on stdin, stdout and stderr, and close fd.

Detailed Description

open a pseudo-terminal pair, and make one a process's terminal.

pseudo-terminals: /dev/ptmx and /dev/pts/N.

a terminal app (mimir) opens /dev/ptmx and gets the master side of a new pair. the program it runs (a shell) uses the slave side, /dev/pts/N, as its terminal: the same termios settings, job control ioctls and window size as the console. bytes the master writes go through the slave's line discipline (line editing, echo, the signal keys) and are read by the slave; bytes the slave writes are read by the master.

the user interface is the Linux one: TIOCGPTN gives N, TIOCSPTLCK with 0 unlocks the slave (unlockpt), TIOCSWINSZ sets the size and sends SIGWINCH to the foreground process group.

limits: VTIME is not used (a read with VMIN 0 does not wait at all). the master's writes wait when the slave does not read; a terminal app that also reads the master in the same thread uses O_NONBLOCK and poll.

Function Documentation

◆ openpty()

int openpty ( int * master,
int * slave,
char * name,
const struct termios * settings,
const struct winsize * size )

open a new pseudo-terminal pair.

Parameters
masterreceives the master fd.
slavereceives the slave fd.
namereceives the slave's path, if not NULL (at least 16 bytes).
settingsthe slave's termios, if not NULL.
sizethe window size, if not NULL.
Returns
0, or -1 with errno set.

◆ login_tty()

int login_tty ( int fd)

make fd the terminal of the calling process: start a new session, make fd its controlling terminal, put fd on stdin, stdout and stderr, and close fd.

for the child of a terminal app, before execve.

Returns
0, or -1 with errno set.