5

I'd like to know how to create a terminal device to simulate a piece of hardware connected through a serial port. Basically, tty device with a certain baud rate that can be read from and written to between two processes. From what I understand, a psuedo-terminal is what I'm looking for, and the makedev can apparently make one.

I've also found the following set of instructions:

su to root
cd /dev
mkdir pty
mknod pty/m0 c 2 0
mknod pty/s0 c 3 0
ln -s pty/m0 ttyp0
ln -s pty/s0 ptyp0
chmod a+w pty/m0 pty/s0

Is there a better way of making pseudo-terminal, or is this pretty much the standard way of make one in the shell?

sj755
  • 1,115

1 Answers1

4

That's probably how pty device files get created, but you don't want to do that whenever you want a pty. Any given machine usually has a complement of pty device files already created.

Pseudo TTYs are fairly OS specific and you don't mention what you want to do this on. For a modern linux, I'd take a look at openpty(3). You can find working example code in the OpenSSH source code, sshpty.c. You will probably have to find code that calls pty_allocate() to fully understand.