[comp.unix.questions] Changing directories in the background

gheim@eng.auburn.edu (Greg Heim) (04/30/91)

Howdy,

I just tried the following:

   cd /new/dir &

by accident and my directory didn't change.  Can anybody tell me what happens
internally here?


Thanks in advance,

Greg


x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x
|  Name: Greg Heim                                                         |
|  Address: gheim@eng.auburn.edu                                           | 
|  Description: Student, Applied Mathematics, Gasp!                        |
|  Catchy Net Phrase: Ignorance is a bitch.                                |
x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x

jc@raven.bu.edu (James Cameron) (05/01/91)

>>>>> On 30 Apr 91 05:52:42 GMT, gheim@eng.auburn.edu (Greg Heim) said:
Greg> Nntp-Posting-Host: lab14.eng.auburn.edu

Greg> Howdy,

Greg> I just tried the following:

Greg>    cd /new/dir &

Greg> by accident and my directory didn't change.  Can anybody tell me what happens
Greg> internally here?


Greg> Thanks in advance,

Greg> Greg



Well, to put it simply the & creates a child of the original, inherenting
the parents stuff, but not causing anything to happen to the parent.

Graphically, looks something like this:

____________________________________________________________________
|                                                                  |
|     Parent - (shell in this case)  certain commands work on this |
|              while others cause it to bear children (another     |
|              call for sex safe!)                                 |
___________________________________________________________________
         |                   |                     |
         |                   |                     |
         |                   |                     |
         |                   |                     |
   ----------------   ---------------    --------------------
   | shell scripts|   |  background |    |  Those programs  |
   ----------------   |     jobs    |    |  which do exec   |
               /\     ---------------    |      calls       |
                \\          /\           --------------------
                 \\         ||           /|
                  \\        ||          //
                   \\       ||         //
                    \\      ||        //
                     \\     ||       //
                      \\    ||      //

                         Children

Now, I am sure that others with have something to say about
this, but that is what I know....*8-)

jc
--
					-- James Cameron  (jc@raven.bu.edu)

Signal Processing and Interpretation Lab.  Boston, Mass  (617) 353-2879
------------------------------------------------------------------------------
"But to risk we must, for the greatest hazard in life is to risk nothing.  For
the man or woman who risks nothing, has nothing, does nothing, is nothing."
	(Quote from the eulogy for the late Christa McAuliffe.)

c60b-1eq@e260-1g.berkeley.edu (Noam Mendelson) (05/01/91)

In article <gheim.910430005242@lab14.eng.auburn.edu> gheim@eng.auburn.edu (Greg Heim) writes:
>I just tried the following:
>   cd /new/dir &
>by accident and my directory didn't change.  Can anybody tell me what happens
>internally here?

If cd is run in the background, the newly spawned process gets the new
cwd, not your shell.  Each process has its own cwd.  The process that's
spawned is terminated immediately (I would hope), so there's no harm done.

-- 
+==========================================================================+
| Noam Mendelson   ..!ucbvax!web!c60b-1eq       | "I haven't lost my mind, |
| c60b-1eq@web.Berkeley.EDU                     |  it's backed up on tape  |
| University of California at Berkeley          |  somewhere."             |