home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / internal / 1715 < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.3 KB  |  62 lines

  1. Newsgroups: comp.unix.internals
  2. Path: sparky!uunet!usc!sdd.hp.com!caen!hellgate.utah.edu!fcom.cc.utah.edu!park.uvcc.edu!ns.novell.com!gateway.novell.com!thisbe.Eng.Sandy.Novell.COM!terry
  3. From: terry@thisbe.Eng.Sandy.Novell.COM (Terry Lambert)
  4. Subject: Re: cd-ing to a dir using a process, then staying there on exit.
  5. Message-ID: <1992Aug20.163507.4449@gateway.novell.com>
  6. Sender: news@gateway.novell.com (NetNews)
  7. Nntp-Posting-Host: thisbe.eng.sandy.novell.com
  8. Organization: Novell NPD -- Sandy, UT
  9. References: <BtA8CG.ME4@encore.com>
  10. Date: Thu, 20 Aug 1992 16:35:07 GMT
  11. Lines: 49
  12.  
  13. In article <BtA8CG.ME4@encore.com> mpalmer@encore.com (Mike Palmer) writes:
  14. >Can anyone suggest a way for a process to cd to a dir & stay there when the \
  15. >process exits.
  16.  
  17. I assume that what you mean is that you want the parent to have the childs
  18. directory after the child exits...  sure!  It's easy!
  19.  
  20. 1)    Inside the child process, use chdir() to change to the desired
  21.     directory.
  22.  
  23. 2)    Open up /dev/kmem, /dev/mem, and potentially /dev/swap.
  24.  
  25. 3)    Find the proc struct for your process.
  26.  
  27. 4)    Find the u struct associated with your process' proc struct.
  28.  
  29. 5)    Get the locked vnode number for the process' cwd from the u struct.
  30.  
  31. 6)    Repeat steps 3 through 5 for the parent process as well.
  32.  
  33. 7)    To avoid having to reverse map the parent's cwd to a file name and
  34.     to avoid dorking the reference count on the vnodes and locking up
  35.     your file system, swap cwd's between the parent and the child
  36.     process.  Do this by writing the childs vnode number into the
  37.     parent's u struct, and the parent's into the childs.  This is the
  38.     sneaky bit.
  39.  
  40. 8)    Close /deb/kmem and anything else you had to have open to read
  41.     and write the proc tables, the proc structs, and the u structs.
  42.  
  43. 9)    Reset the childs cwd (using chdir()) to the desired directory.
  44.     This will avoid a potential credentials problem on process exit.
  45.  
  46. 10)    Exit the child process.
  47.  
  48.  
  49. Or if you were lazy, you could type 'cd' in the parent, which is probably a
  50. shell.  If the parent isn't a shell, you could popen() the child, read(),
  51. the child could write() it's cwd on exit, and the parent could chdir() to
  52. the value returned by read().
  53.  
  54.  
  55.                     Terry Lambert
  56.                     terry_lambert@gateway.novell.com
  57.                     terry@icarus.weber.edu
  58.  
  59. ---
  60. Disclaimer:  Any opinions in this posting are my own and not those of
  61. my present or previous employers.
  62.