1

I'm attempting to determine how many terminal windows are open, as described in this Q&A answer. However there doesn't seem to be a /dev/pts on Mac OSX. Is there an alternative to this?

2

The answer you cite proposes to count how many terminal windows are open by counting the number of extant pseudo-terminals. I don't consider that to be a correct answer: it actually counts the number of terminal windows PLUS the number of remote logins, screen or tmux windows, script or expect sessions, and so on. To really count just the number of terminal windows, you would have to do something to exclude all those other things from the count. Perhaps you could check each pty to see if a terminal application such as Terminal.app for MacOS is the parent process of any process listed as running on that tty (use ps -ft<name of tty>).

Regardless, the direct answer to your question "Is there a /dev/pts alternative on Mac OSX?" is yes, terminal windows on MacOS run in pseudo ttys just like they do on other operating systems. As you can see from the output of tty running under one of them, the names of these ptys follow the pattern /dev/ttys<three digits>, and as you can see fromsome quick experiments with ls, only the ones that are currently allocated actually exist in /dev. Therefore, yes, the same trick of checking which ptys exists in /dev works under MacOS. (Note that this trick does not work under every operation system: under some operating systems: all of the possible pty names always exist in /dev regardless of whether they are allocated or not.)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.