Getting tty name without using ttyname(3)

Helge Egelund Rasmussen her at compel.UUCP
Thu Feb 15 20:37:32 AEST 1990


I need to write a replacement for the SYSV release 3 ttyname(3) function.
The reason is that the ttyname call is veeeery slow on our machine 
(5 to 10 seconds).

As far as I can see by prof'ing a test program, ttyname calls stat(2)
on the files in /dev until it finds the correct tty (its doing about 300
stat calls!).

Presumably ttyname is comparing the 'st_rdev' field in the stat structure with 
something identifying the current tty.

I'd like to know what the ttyname call really is doing.

I need the call to identify the terminal used by the current process 
(for logging purposes), so it's not enough to get "/dev/tty" as answer..

Any help would be appreciated.

Helge

---
Helge E. Rasmussen  .  PHONE + 45 31 37 11 00  .  E-mail:  her at compel.dk
Compel A/S          .  FAX   + 45 31 37 06 44  . 
Copenhagen, Denmark



More information about the Comp.unix.wizards mailing list