Path: utzoo!attcan!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.unix.wizards Subject: Re: Getting tty name without using ttyname(3) Keywords: ttyname Message-ID: <1990Feb16.040357.2555@virtech.uucp> Date: 16 Feb 90 04:03:57 GMT References: <673@compel.UUCP> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 37 In article <673@compel.UUCP> her@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 | +-----------------------------------------------------------------------+