Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcmgw!rdg From: rdg@hpfcmgw.HP.COM (Rob Gardner) Newsgroups: comp.sys.hp Subject: Re: pwd Message-ID: <1080108@hpfcmgw.HP.COM> Date: 21 Dec 89 22:27:18 GMT References: <263@zircon.UUCP> Organization: HP Fort Collins, CO Lines: 26 > How does /bin/pwd work? There is no kernel call to find your current > directory in UNIX, so it has to do some backhanded peeking in memory > somewhere, probably in kernel memory. This suspicion is reinforced by > /bin/pwd being setuid to root on my system (HP-UX, System V > compatible). That's not how it currently works. The actual method is pretty disgusting, but here's a brief explanation of how it does it: Open your parent directory (..) and read entries until you find one whose inode matches the inode of your current directory (.). Now you know the (base)name of your current directory. Now you chdir(".."), and repeat to find out the basename of the parent. You keep doing this until you get to /, and build up the pathname as you go. This is, of course, a very simplistic explanation, since there are cases that require special handling. I think that there will be a kernel call in a "future" release. Rob Gardner hplabs!hpfcmr!rdg Hewlett Packard or rdg%hpfcmr@hplabs.hp.com Fort Collins, Colorado 303-229-2048 80525-9599 "Ask me about Home Brewing"