home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.internals
- 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
- From: terry@thisbe.Eng.Sandy.Novell.COM (Terry Lambert)
- Subject: Re: cd-ing to a dir using a process, then staying there on exit.
- Message-ID: <1992Aug20.163507.4449@gateway.novell.com>
- Sender: news@gateway.novell.com (NetNews)
- Nntp-Posting-Host: thisbe.eng.sandy.novell.com
- Organization: Novell NPD -- Sandy, UT
- References: <BtA8CG.ME4@encore.com>
- Date: Thu, 20 Aug 1992 16:35:07 GMT
- Lines: 49
-
- In article <BtA8CG.ME4@encore.com> mpalmer@encore.com (Mike Palmer) writes:
- >Can anyone suggest a way for a process to cd to a dir & stay there when the \
- >process exits.
-
- I assume that what you mean is that you want the parent to have the childs
- directory after the child exits... sure! It's easy!
-
- 1) Inside the child process, use chdir() to change to the desired
- directory.
-
- 2) Open up /dev/kmem, /dev/mem, and potentially /dev/swap.
-
- 3) Find the proc struct for your process.
-
- 4) Find the u struct associated with your process' proc struct.
-
- 5) Get the locked vnode number for the process' cwd from the u struct.
-
- 6) Repeat steps 3 through 5 for the parent process as well.
-
- 7) To avoid having to reverse map the parent's cwd to a file name and
- to avoid dorking the reference count on the vnodes and locking up
- your file system, swap cwd's between the parent and the child
- process. Do this by writing the childs vnode number into the
- parent's u struct, and the parent's into the childs. This is the
- sneaky bit.
-
- 8) Close /deb/kmem and anything else you had to have open to read
- and write the proc tables, the proc structs, and the u structs.
-
- 9) Reset the childs cwd (using chdir()) to the desired directory.
- This will avoid a potential credentials problem on process exit.
-
- 10) Exit the child process.
-
-
- Or if you were lazy, you could type 'cd' in the parent, which is probably a
- shell. If the parent isn't a shell, you could popen() the child, read(),
- the child could write() it's cwd on exit, and the parent could chdir() to
- the value returned by read().
-
-
- Terry Lambert
- terry_lambert@gateway.novell.com
- terry@icarus.weber.edu
-
- ---
- Disclaimer: Any opinions in this posting are my own and not those of
- my present or previous employers.
-