Factor out into a function the current number of PTY's detection code