Getting tty name without using ttyname(3)

Conor P. Cahill cpcahil at virtech.uucp
Fri Feb 16 15:03:57 AEST 1990


In article <673 at compel.UUCP> her at compel.UUCP (Helge Egelund Rasmussen) writes:
>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!).

ttyname() does a fstat on the file descriptor that it is passed and then
looks throught the /dev directory (using the stat()s you mentioned) looking
for a matching entry.

If you really need the performance gain, you could make a new directory say
/dev/only_ttys which contains links to all the tty devices in /dev.  You
could then modify ttyname() (or write your own) that would look through
this directory instead (of course it would have to drop off the "only_ttys/"
in order to be compatible with standard ttyname().


Another, slightly more dangerous, but more compatible method would be to:

	put your system into single user mode

	make a copy of the entire /dev directory hierarchy in another directory

	mv /dev /dev.old

	mkdir /dev

	move tty devices from /dev.old to /dev

	move rest of the stuff back to /dev

This solves the problem by placing all the tty devices first in the directory
so they should be found sooner.
-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list