Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!ucbvax!hplabs!otter!hpubrcf!ken From: ken@hpubrcf.HP.COM (Ken Green) Newsgroups: comp.sys.hp Subject: Re: pwd Message-ID: <120004@hpubrcf.HP.COM> Date: 21 Dec 89 10:24:32 GMT References: <263@zircon.UUCP> Organization: HP UK Response Center Lines: 19 > > 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). If you look in the header file /usr/include/sys/user.h, which describes the contence of a processes u_area you'll find that it contains a pointer to the vnode for the current directory. #Guess mode on This must point to a directory, you could then open .. the parent and find the directory name from the inode number, of course you'd need to keep going till you got to the processes root directory ( this too is stored in the u_area ). #Guess mode off