home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 15064 < prev    next >
Encoding:
Text File  |  1992-12-30  |  2.5 KB  |  57 lines

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