Solaris pty's

A pty--also known as pts, pt's, pseudo-tty's--is a remote (pseudo) terminal. Prior to Solaris 8, the default maximum value of pty's is 48. Beginning with Solaris 8, the number of pseudo-terminals increases on demand, as long as the syseventd daemon is running.

Attempting to exceed this value may result in errors such as:

Warning: no access to tty (Bad file number).

Sep  4 12:36:58 hostname sshd[16676]: error: /dev/ptmx: No such device
Sep  4 12:36:58 hostname sshd[16678]: error: session_pty_req: session 0 alloc failed

Determine maximum number of pty's:
# echo "pt_cnt/D" | adb -k
physmem 1f4e9
pt_cnt:
pt_cnt:        48

# ls /dev/pts | wc -l
      48

The following is a Bourne shell script to determine the current number of pty's in use and the maximun number of pty's (thanks to Ton Voon for showing me how to determine the current number of pty's in use):

#!/bin/sh
                                                                               
PTYS_IN_USE=0
TOTAL_PTYS=`ls /dev/pts | wc -l | sed 's/ //g`
for PTY in /dev/pts/*
do
   [ -n "`fuser $PTY 2>/dev/null`" ] && PTYS_IN_USE=`expr $PTYS_IN_USE + 1`
done
echo "PTYs in use: $PTYS_IN_USE"
echo " Total PTYs: $TOTAL_PTYS"

Example output:

PTYs in use: 7
 Total PTYs: 48

The following Bourne shell script shows the PIDs in use for each of the system's pty's:

#!/bin/sh

for PTY in `ls /dev/pts | sort -n` ; do
   echo "/dev/pts/$PTY"
   PIDS=`fuser /dev/pts/$PTY 2>&1 | awk -F: '{ print $2 }' | tr -d '[a-z][A-Z]'`
   ps -fp "$PIDS"
   echo
done

Example output:
...
/dev/pts/46
     UID   PID  PPID  C    STIME TTY      TIME CMD
    root 13009 12508  0 09:56:16 pts/46   0:00 -sh
    root  1141 13009  0 10:58:48 pts/46   0:00 /bin/sh ./pts_to_pid
...

Increasing number of pty's:

1. Add set pt_cnt = number to /etc/system
Note: there is no defined limit to the number of pty's that you create; values greater than 3000 have been used in practice. I recommend setting the number of ptys at multiples of 256 until you reach a comfortable limit.

2. Perform a reconfiguration reboot.

If a reboot (but not reconfiguration reboot) is performed after the kernel parameter change, the pty device links can be created with drvconfig;devlinks

Increasing pty's without a reboot

At least with my tests on a Solaris 2.6 system, this is not possible. This link claims it is possible, but I followed the steps, and it did not work.

# adb -k -w /dev/ksyms /dev/mem
physmem 7dd2c
pt_cnt/D
pt_cnt:
pt_cnt:         48
pt_cnt?W400
pt_cnt:         0x30            =       0x400
$q

# drvconfig;devlinks

After running drvconfig;devlinks, /dev/pts was not populated with the additional pty's, so I created them myself.

#!/bin/sh

# Create pty's 48 - 1023
PTY=48
ENDING_PTY=1023

while [ "$PTY" -le "$ENDING_PTY" ] ; do
   mknod /devices/pseudo/pts@0:$PTY c 24 $PTY
   chmod 644 /devices/pseudo/pts@0:$PTY
   chgrp sys /devices/pseudo/pts@0:$PTY
   ln -s ../../devices/pseudo/pts@0:$PTY /dev/pts/$PTY
   chgrp -h root /dev/pts/$PTY
   PTY=`expr $PTY + 1`
done

Unfortunately, this does not work. This link explains why.

More information:
How can I have more than 48 pseudo-ttys?

Solaris Kernel Tuning

Back to brandonhutchinson.com.
Last modified: 2007/10/16