home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / programm / 4327 < prev    next >
Encoding:
Internet Message Format  |  1992-08-16  |  2.6 KB

  1. Xref: sparky comp.unix.programmer:4327 comp.unix.wizards:3636
  2. 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
  3. From: andrewfg@coral.aifh.ed.ac.uk (Andrew Fitzgibbon)
  4. Newsgroups: comp.unix.programmer,comp.unix.wizards
  5. Subject: Re: How can a program know where it was invoked?
  6. Message-ID: <ANDREWFG.92Aug16165345@coral.aifh.ed.ac.uk>
  7. Date: 16 Aug 92 15:53:45 GMT
  8. References: <bmckeon.713727455@unix1.tcd.ie> <1992Aug13.182509.10985@nic.umass.edu>
  9.     <1992Aug14.183521.1704@sco.com> <1992Aug15.022032.13233@Princeton.EDU>
  10. Sender: news@aifh.ed.ac.uk (Network News Administrator)
  11. Organization: Edinburgh University Robotics/Vision Group
  12. Lines: 49
  13. In-Reply-To: spencer@stroke.Princeton.EDU's message of 15 Aug 92 02:20:32 GMT
  14.  
  15.  
  16.  
  17. Someone wanted to know how to find out where a program was being run from.
  18.  
  19. This is a fairly crude attempt, which looks at memory mapped pages and decides
  20. that if one of these is the executable, it must be the right one.  Given the
  21. inode it then converts this to a filename using `find' -- is there a better way
  22. to do this?
  23.  
  24. % ofiles 2125
  25.  ...
  26.  mmap   = file inode 22047 on nfs fs 33291 (/am/jewel/home/jewel1)
  27.  mmap   = file inode 9701 on nfs fs 33282 (/usr)
  28.  mmap   = file inode 9701 on nfs fs 33282 (/usr)
  29.  mmap   = file inode 3848 on nfs fs 33291 (/am/jewel/home/jewel1)
  30.  
  31. % gnufind /am/jewel/home/jewel1 -xdev -inum 3848 -o -inum 22047
  32. /am/jewel/home/jewel1/openwin3/bin/dsdm
  33. /am/jewel/home/jewel1/openwin3/lib/libX11.so.4.3
  34. < Took 49 seconds >
  35.  
  36. % gnufind /usr -xdev -inum 9701
  37. /usr/lib/libc.so.1.6
  38. < Took 33 seconds >
  39.  
  40. # Now just need to check which of the three is the executable...
  41.  
  42. % 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
  43. /am/jewel/home/jewel1/openwin3/bin/dsdm:        sparc demand paged dynamically linked executable not stripped
  44.  
  45. < Ta daaa...  But what if somebody removes the executable?>
  46.  
  47. % cp /usr/bin/sleep .
  48. % sleep 4000 &
  49. [1] 2340
  50. % rm sleep
  51. % ofiles 2340
  52.  mmap   = file inode 1279 on nfs fs 33290 (/am/jewel/home/jewel2)
  53.  mmap   = file inode 9701 on nfs fs 33282 (/usr)
  54. % find . -inum 1279
  55. ./.nfs875D
  56. % Bloody hell !! I've always wondered why they were lying around before.
  57.  
  58. \end{experiments}
  59. --
  60. Andrew Fitzgibbon,                     | "If it ain't broke, don't fix it"
  61. Department of Artificial Intelligence, |             - traditional (c1950)
  62. Edinburgh University.                  | "A stitch in time saves nine."
  63. andrewfg@uk.ac.ed.aifh                 |             - traditional (c1590)
  64.