home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.programmer:4327 comp.unix.wizards:3636
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!concert!gatech!darwin.sura.net!Sirius.dfn.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!uknet!edcastle!aifh!helium!andrewfg
- From: andrewfg@coral.aifh.ed.ac.uk (Andrew Fitzgibbon)
- Newsgroups: comp.unix.programmer,comp.unix.wizards
- Subject: Re: How can a program know where it was invoked?
- Message-ID: <ANDREWFG.92Aug16165345@coral.aifh.ed.ac.uk>
- Date: 16 Aug 92 15:53:45 GMT
- References: <bmckeon.713727455@unix1.tcd.ie> <1992Aug13.182509.10985@nic.umass.edu>
- <1992Aug14.183521.1704@sco.com> <1992Aug15.022032.13233@Princeton.EDU>
- Sender: news@aifh.ed.ac.uk (Network News Administrator)
- Organization: Edinburgh University Robotics/Vision Group
- Lines: 49
- In-Reply-To: spencer@stroke.Princeton.EDU's message of 15 Aug 92 02:20:32 GMT
-
-
-
- Someone wanted to know how to find out where a program was being run from.
-
- This is a fairly crude attempt, which looks at memory mapped pages and decides
- that if one of these is the executable, it must be the right one. Given the
- inode it then converts this to a filename using `find' -- is there a better way
- to do this?
-
- % ofiles 2125
- ...
- mmap = file inode 22047 on nfs fs 33291 (/am/jewel/home/jewel1)
- mmap = file inode 9701 on nfs fs 33282 (/usr)
- mmap = file inode 9701 on nfs fs 33282 (/usr)
- mmap = file inode 3848 on nfs fs 33291 (/am/jewel/home/jewel1)
-
- % gnufind /am/jewel/home/jewel1 -xdev -inum 3848 -o -inum 22047
- /am/jewel/home/jewel1/openwin3/bin/dsdm
- /am/jewel/home/jewel1/openwin3/lib/libX11.so.4.3
- < Took 49 seconds >
-
- % gnufind /usr -xdev -inum 9701
- /usr/lib/libc.so.1.6
- < Took 33 seconds >
-
- # Now just need to check which of the three is the executable...
-
- % file /am/jewel/home/jewel1/openwin3/bin/dsdm /am/jewel/home/jewel1/openwin3/lib/libX11.so.4.3 /usr/lib/libc.so.1.6 | grep -v library | grep executable
- /am/jewel/home/jewel1/openwin3/bin/dsdm: sparc demand paged dynamically linked executable not stripped
-
- < Ta daaa... But what if somebody removes the executable?>
-
- % cp /usr/bin/sleep .
- % sleep 4000 &
- [1] 2340
- % rm sleep
- % ofiles 2340
- mmap = file inode 1279 on nfs fs 33290 (/am/jewel/home/jewel2)
- mmap = file inode 9701 on nfs fs 33282 (/usr)
- % find . -inum 1279
- ./.nfs875D
- % Bloody hell !! I've always wondered why they were lying around before.
-
- \end{experiments}
- --
- Andrew Fitzgibbon, | "If it ain't broke, don't fix it"
- Department of Artificial Intelligence, | - traditional (c1950)
- Edinburgh University. | "A stitch in time saves nine."
- andrewfg@uk.ac.ed.aifh | - traditional (c1590)
-