Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

pty(3) [freebsd man page]

PTY(3)							   BSD Library Functions Manual 						    PTY(3)

NAME
openpty, forkpty -- auxiliary functions to obtain a pseudo-terminal LIBRARY
System Utilities Library (libutil, -lutil) SYNOPSIS
#include <sys/types.h> #include <sys/ioctl.h> #include <termios.h> #include <libutil.h> int openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp); int forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp); DESCRIPTION
The function openpty() attempts to obtain the next available pseudo-terminal from the system (see pty(4)). If it successfully finds one, it subsequently changes the ownership of the slave device to the real UID of the current process, the group membership to the group ``tty'' (if such a group exists in the system), the access permissions for reading and writing by the owner, and for writing by the group, and invali- dates any current use of the line by calling revoke(2). If the argument name is not NULL, openpty() copies the pathname of the slave pty to this area. The caller is responsible for allocating the required space in this array. If the arguments termp or winp are not NULL, openpty() initializes the termios and window size settings from the structures these arguments point to, respectively. Upon return, the open file descriptors for the master and slave side of the pty are returned in the locations pointed to by amaster and aslave, respectively. The forkpty() function first calls openpty() to obtain the next available pseudo-terminal from the system. Upon success, it forks off a new process. In the child process, it closes the descriptor for the master side of the pty, and calls login_tty(3) for the slave pty. In the parent process, it closes the descriptor for the slave side of the pty. The arguments amaster, name, termp, and winp have the same meaning as described for openpty(). RETURN VALUES
The openpty() function returns 0 on success, or -1 on failure. The forkpty() function returns -1 on failure, 0 in the slave process, and the process ID of the slave process in the parent process. ERRORS
The openpty() function may fail and set the global variable errno for any of the errors specified for the grantpt(3), posix_openpt(3), ptsname(3), and unlockpt(3) functions and the revoke(2) system call. In addition to this, forkpty() may set it to any value as described for fork(2). SEE ALSO
chmod(2), chown(2), fork(2), getuid(2), open(2), revoke(2), login_tty(3), pty(4), termios(4), group(5) BSD
December 29, 1996 BSD

Check Out this Related Man Page

OPENPTY(3)						   BSD Library Functions Manual 						OPENPTY(3)

NAME
openpty, login_tty, forkpty -- tty utility functions LIBRARY
System Utilities Library (libutil, -lutil) SYNOPSIS
#include <util.h> int openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp); int login_tty(int fd); pid_t forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp); DESCRIPTION
The openpty(), login_tty(), and forkpty() functions perform manipulations on ttys and pseudo-ttys. The openpty() function finds an available pseudo-tty and returns file descriptors for the master and slave in amaster and aslave. If name is non-null, the filename of the slave is returned in name. If termp is non-null, the terminal parameters of the slave will be set to the val- ues in termp. If winp is non-null, the window size of the slave will be set to the values in winp. The login_tty() function prepares for a login on the tty fd (which may be a real tty device, or the slave of a pseudo-tty as returned by openpty()) by creating a new session, making fd the controlling terminal for the current process, setting fd to be the standard input, out- put, and error streams of the current process, and closing fd. The forkpty() function combines openpty(), fork(), and login_tty() to create a new process operating in a pseudo-tty. The file descriptor of the master side of the pseudo-tty is returned (to the parent process only) in amaster. The filename of the slave is returned (to both the parent and child processes) in name if name is non-null. The termp and winp parameters, if non-null, will determine the terminal attributes and window size of the slave side of the pseudo-tty. RETURN VALUES
If a call to openpty(), login_tty(), or forkpty() is not successful, -1 is returned and errno is set to indicate the error. Otherwise, openpty(), login_tty(), and the child process of forkpty() return 0, and the parent process of forkpty() returns the process ID of the child process. FILES
/dev/[pt]ty[p-zP-T][0-9a-zA-Z] ERRORS
openpty() will fail if: [ENOENT] There are no available ttys. [EPERM] The caller was not the superuser and the ptm(4) device is missing or not configured. login_tty() will fail if ioctl() fails to set fd to the controlling terminal of the current process. forkpty() will fail if either openpty() or fork() fails. SEE ALSO
fork(2) BSD
November 28, 2008 BSD
Man Page