LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   About current working directory (http://www.linuxquestions.org/questions/programming-9/about-current-working-directory-550651/)

George2 05-02-2007 09:33 AM

About current working directory
 
Hello everyone,


If I create a file (whose name is "foo") using constant string "./foo", I am wondering under which directory should file foo be created, i.e. what/where is the current '.' directory? I think it should be current working directory, which could be get and set by Linux API getcwd/chdir?

For example, if I use Linux API chdir to change current working directory to /temp, the file foo will be created under /temp. Is my understanding correct?


thanks in advance,
George

kaz2100 05-02-2007 10:10 AM

Hya,

If you make a file without absolute path, it will go wherever relative to "PWD" shell variable points.

I guess your understanding is correct.

Happy Penguins!

taylor_venable 05-02-2007 10:56 AM

Quote:

Originally Posted by kaz2100
If you make a file without absolute path, it will go wherever relative to "PWD" shell variable points.

At the start of process execution, the kernel creates a process descriptor which will identify the process. This object in memory contains a structure which contains information about the process' current directory and root directory (among other information). This information is what allows processes to change their current directory (as the OP indicates) or to be chroot(2)'ed. Initially this information is inherited from the parent process, which in the case of running the program from the CLI is (basically) the shell's variable PWD. Or if it's spawned from another process, the current working directory of that process is inherited.

Also: yes, George2, you're reasoning is correct.

George2 05-02-2007 08:33 PM

Thanks kaz2100!


Quote:

Originally Posted by kaz2100
Hya,

If you make a file without absolute path, it will go wherever relative to "PWD" shell variable points.

I guess your understanding is correct.

Happy Penguins!

1) current working direcroty -- in which the man page of chdir mentioned always;
2) . direcroty

Are they the same thing? I see chdir always mentions 1 but never mention 2.


regards,
George

George2 05-02-2007 08:34 PM

Thanks for your great answer taylor_venable! Your reply gives me in-depth insight. Cool!


Quote:

Originally Posted by taylor_venable
At the start of process execution, the kernel creates a process descriptor which will identify the process. This object in memory contains a structure which contains information about the process' current directory and root directory (among other information). This information is what allows processes to change their current directory (as the OP indicates) or to be chroot(2)'ed. Initially this information is inherited from the parent process, which in the case of running the program from the CLI is (basically) the shell's variable PWD. Or if it's spawned from another process, the current working directory of that process is inherited.

Also: yes, George2, you're reasoning is correct.

1) current working direcroty -- in which the man page of chdir mentioned always;
2) . direcroty

Are they the same thing? I see chdir always mentions 1 but never mention 2.


regards,
George

taylor_venable 05-02-2007 09:47 PM

Quote:

Originally Posted by George2
Thanks for your great answer taylor_venable! Your reply gives me in-depth insight. Cool!

You're most welcome. :)

Quote:

Originally Posted by George2
1) current working direcroty -- in which the man page of chdir mentioned always;
2) . direcroty

Are they the same thing? I see chdir always mentions 1 but never mention 2.

Just as ".." is an alias for the parent directory, "." is (practically speaking) the same as the current working directory.


All times are GMT -5. The time now is 06:23 AM.