home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!gatech!udel!news.udel.edu!darwin.sura.net!convex!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: how to change shell's PWD(directory) from a C program?
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1992Dec30.194519.25125@news.eng.convex.com>
- Date: Wed, 30 Dec 1992 19:45:19 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <1hqe2cINN6ot@usenet.INS.CWRU.Edu> <C02648.Jq@bc3.GUN.de>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 39
-
- From the keyboard of ktf@bc3.GUN.de (Klaus ter Fehn):
- :> Here is what I want to do: UPon the termination of my program, I
- :>want to change to another directory . Normally, a program exit to the
- :>directory that invoke it.
- :
- :Because of the current newsgroup (comp.unix.questions) I assume, that
- :you're programming under the UNIX-environment. Note, that the PWD (Path
- :of Working Directory) is an environment-held information of a process.
- :Each process gets a copy of the environment of it's parent-process at
- :startup-time. So if you call the cd() funktion from within a C-Program,
- :only the PWD of the C-program-process is changed. When you exit this
- :program, you are returning to the parent-process (most cases: the
- :shell). It's PWD information was not changed, because you only changed
- :the child's copy.
-
- No, $PWD is not defined by the O/S. Some shells maintain it. Many do
- not. Certainly the chdir(2) function from C will not maintain it.
- Therefore, you can't possibly rely upon it.
-
- Now, your cwd is indeed a process attribute, often stored as a struct
- vnode * within your user structure in the field u_cdir. But that's not
- a name -- it's a vnode pointer. That won't help you.
-
- If you want to know how to change your parent, that's a FAQ. The short
- answer is you can't. The long answer is you can do one of around three
- things:
-
- poke your parent's cdir in the kernel. a very bad idea.
- have your parent eval your output
- stuff a cd into your input buffer with TIOCSTI
-
- The latter approach is the one used by the PD program, dired.
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
-
- "* Unix is a footnote of AT&T Bell Laboratories."
- --Barry Shein
-