LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-02-2007, 09:33 AM   #1
George2
Member
 
Registered: Oct 2003
Posts: 354

Rep: Reputation: 30
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
 
Old 05-02-2007, 10:10 AM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,430

Rep: Reputation: 83
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!
 
Old 05-02-2007, 10:56 AM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 40
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.
 
Old 05-02-2007, 08:33 PM   #4
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
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
 
Old 05-02-2007, 08:34 PM   #5
George2
Member
 
Registered: Oct 2003
Posts: 354

Original Poster
Rep: Reputation: 30
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
 
Old 05-02-2007, 09:47 PM   #6
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 40
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change current working directory in C++? g4j31a5 Programming 4 05-09-2007 10:18 PM
Bash to find and disect current working Directory carl0ski Linux - General 4 10-28-2006 04:36 AM
how do I find out the current working directory? nodger Programming 2 12-26-2004 11:28 AM
current working directory in ksh prompt brian0918 Linux - Newbie 2 06-03-2003 04:34 PM
current working directory in ksh prompt brian0918 Linux - Software 2 06-03-2003 01:50 PM


All times are GMT -5. The time now is 10:07 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration