PTY(3)
π NAME π
okay bestie, welcome to the PTY(3) page from the Library Functions Manual β¨ this is all about openpty, forkpty β auxiliary functions to obtain a pseudo-terminal π«Ά
πΈ LIBRARY πΈ
System Utilities Library (libutil, -lutil) β yes, that means you link with -lutil, iykyk π
β¨ 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 π¦
so openpty() is doing main character work: it attempts to obtain the next available pseudo-terminal from the system (peep pty(4) for the lore) π
if it successfully finds one, it then changes the ownership of the slave device to the real UID of the current process, changes the group membership to the group βttyβ (if such a group exists in the system), sets the access permissions for reading and writing by the owner, and for writing by the group, and invalidates 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 β not me, not the pty, you bestie π
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 β¨
forkpty() is like openpty() with extra drama: first it 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 π
openpty() returns 0 on success, or -1 on failure.
forkpty() returns -1 on failure, 0 in the slave process, and the process ID of the slave process in the parent process. periodt π
π ERRORS π
openpty() may fail and set the global variable errno for any of the errors specified for the grantpt(3), posix_openpt(2), 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 π
π HISTORY π
the openpty() and forkpty() functions first appeared in 4.3BSD-Reno β vintage icon behavior, no cap β
π BUGS π
okay this is the important warning bestie:openpty()writes the slave terminal's name toname, but does not check that sufficient space is available. it is advisable to useptsname(3)instead π¨
xoxo, your Debian bestie β page dated June 2, 2018, filed under PTY(3) π π«Ά
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1996 Joerg Wunsch
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms