From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.5/8.7.3) with ESMTP id EAA12412 for ; Fri, 20 Sep 1996 04:07:30 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id OAA17497; Thu, 19 Sep 1996 14:02:36 -0400 (EDT) Resent-Date: Thu, 19 Sep 1996 14:02:36 -0400 (EDT) Message-Id: Subject: Why's ttyname() called twice on start-up? To: zsh-workers@math.gatech.edu Date: Thu, 19 Sep 1996 20:02:58 +0200 (MET DST) From: Thorsten Meinecke Organization: none. Location: Berlin, Germany X-Mailer: ELM [version 2.4 PL23] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"0bHgt2.0.GH4.wgOGo"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2152 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Being bored the other day, I played a little with strace(1). Even if zsh runs non-interactively, invoked for example by % strace -f zsh -fc exit I discovered to my astonishment a plethora of readdir() calls, all skimming through the /dev directory, not only once, but three times! Turns out that with my old Linux kernel 1.2.13 and libc 5.0.9, the ttyname() function seems to be costly implemented. Things improved since then, under, say, 2.0/5.2.18 only a few getdents() system calls are needed instead of several hundred readdir()s. Ignoring the fact that the implementation of ttyname() is highly system-specific, and its efficiency may vary - can't the second call to it be avoided? [With Linux, it's called a third time anyway, internally by getlogin()] init_io () at init.c:318 (this is 3.0.0) 318 SHTTY = movefd(open(ttyname(0), O_RDWR)); ... setupvals () at init.c:520 520 if (!(ttystrname = ztrdup(ttyname(SHTTY)))) Regards, --Thorsten