I'm currently learning about the TTY system, and I want to create a demo application which opens /dev/pts/ptmx which will create a new terminal, and then have a process create a new session which will open this new terminal and be controlled by it.

But something is very weird. In order to open /dev/pts/ptmx you must be root. Now, when you open /dev/pts/ptmx, you get a file descriptor which you should pass to grantpts, which will "change the owner and mode of the slave ... device corresponding to the master pseudo-terminal corresponding to fd. The user ID of the slave the real UID of the calling process". But the calling process must be run by root in order to open /dev/pts/ptmx, and only there you have the file descriptor... what gives?

  • According to man ptmx, you should be opening /dev/ptmx, not /dev/pts/ptmx (and /dev/ptmx is by default mode 0666).
    – larsks
    May 3 at 2:51
  • See unix.stackexchange.com/questions/492823/… for some interesting commenary on why there are two ptmx device nodes (pointing at the same device).
    – larsks
    May 3 at 2:53


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.