What is the difference between forkpty and openpty?

Basically the title. What is the difference between forkpty and openpty? They seem to do the exact same except that forkpty returns the master and either a parent or child, while openpty returns a master and slave.

From the linked man page:

The forkpty() function combines openpty(), fork(2), and
login_tty() to create a new process operating in a
pseudoterminal. A file descriptor referring to master side of
the pseudoterminal is returned in amaster. If name is not NULL,
the buffer it points to is used to return the filename of the
slave. The termp and winp arguments, if not NULL, will determine
the terminal attributes and window size of the slave side of the
pseudoterminal.

So openpty just opens a pseudoterminal, whereas forkpty opens a pseudoterminal, forks a child process and runs the child process in the newly created pseudoterminal.

1 Like