хендл файла закрывается при выходе из блока.
When a process opens /dev/ptmx, it gets a file descriptor for a pseudoterminal master (PTM), and a pseudoterminal slave (PTS) device is created in the /dev/pts directory. Each file descriptor obtained by opening /dev/ptmx is an independent PTM with its own associated PTS, whose path can be found by passing the descriptor to ptsname(3).
Before opening the pseudoterminal slave, you must pass the master's file descriptor to grantpt(3) and unlockpt(3).
я полагаю, ядро присылает SIGHUP от парного созданного терминала