[clug] Pseudo terminals

David Tulloh david at tulloh.id.au
Wed Jul 18 12:38:34 GMT 2007

Brad Hards wrote:
> On Wednesday 18 July 2007 17:58, Adrian Blake wrote:
>> Within  a Fortran program I can open up a terminal with a system command
>> like:   call system("xterm -T new &" , result)
>> This creates a device   /dev/pty/x   x is some number
>> I then  would like to be able to direct output to that device:  OPEN
>> (UNIT=15, FILE="/dev/pts/x", STATUS="OLD", ACCESS="STREAM") , but how can I
>> determine the value of x?
>> I could do : ps -ax | grep pty/     and then pick the greatest numbered
>> pty.  Clumsy under program control.
>> Any suggestions?
> I haven't tried this, so this is a bit of a stretch, but how about creating 
> the pty yourself, and then passing the pty number to xterm (using -S)
> I'm not sure how you would create the pty in FORTRAN (I think it has to be 
> upper case :-). There is a bit of information in pty(7) about how 
> posix_openpt() works, or maybe you could just create a helper application in 
> C and call that from your FORTRAN app.
> Brad

That looks like a nice clean approach Brad.  Another alternative there 
is the uber-hackish approach, get the xterm to report it's own tty.  In 
crude pseudo code:

$random = some unique random number/string
xterm -T new -e "tty > /tmp/$random; $shell"
$x = read(/tmp/$random);


More information about the linux mailing list