What is the purpose of the BSD pty/tty device files in /dev?

Solution 1:

Backwards compatibility is the reason that these files are on the newest version of macOS. It is there to ensure that programs that expect this way of handling pseudo terminals still work.

You can open the /dev/ptyX# files the same way you would open /dev/ttys### files. You seem to have reversed the slashes in your command - please ensure that you are using forward slashes like this:

screen /dev/ttyw0

Note that this in itself doesn't cause anything to happen. You have only connected to one end of the terminal pair. You would need to connect to other end as well to transfer some data.

As an example you could open one Terminal window and run the command above, and then open another Terminal window and run the command below:

screen /dev/ptyw0

Now if you type something in one window, it appears in the other (and vice versa).

The main factor in adopting the ptmx system was that the old system is very complex for programmers to use correct. It looks deceptively simple, but when you get into it, you'll find that it is actually not.

One of the main problems is in determining which of the /dev/ttyXX files to actually use. I.e. you want to use one that is not in use by others. If you're not very careful, two programs that want to open a new pseudo terminal at the same time could both mistakenly think that the same terminal is not in use by others, and then both start using it - causing all sorts of problems. The ptmx system solves this problem.