Jack Lee
Jack Lee

Reputation: 483

Is a process's current directory equals to its working directory?

Is current directory same as working directory?

when I start a program under the PATH search folders, will the first folder become its current directory?

Upvotes: 1

Views: 518

Answers (3)

Aleksandar Vucetic
Aleksandar Vucetic

Reputation: 14953

"The current directory is distinct from the original directory, which is the one from which the process was started."...as pointed here

Btw, regarding your question title, there is not current or working directory, there is something called "current working directory" (again, from the link above).

Within your application, you can't be sure where your current working directory will be when the application is started, but you can set it if you want.

(my links are .net related, which might not be your technology of choice).

Upvotes: 0

paulsm4
paulsm4

Reputation: 121849

"Current directory" is a property of an active process.

AFAIK, "Current directory", "Current Working Directory" and "Working Directory" are all synonyms for exactly the same thing. They are certainly are in Linux, Java (and arguably .Net) land. In Windows, however, a process can have a different "working directory" for each drive:

A program's "initial directory" is typically one of:

  • the directory you start it in (from the command line),

  • the directory the .exe is located in (if you double-click on it from Windows Explorer), or

  • the directory specified by the desktop link (if you double-click a Windows shortcut)

In other words, "Initial directory" and "the directory the exe is located in" may be the same, or different.

  • A running process's "Initial directory" has nothing directly to do with the "Path".

The path helps the OS find the .exe (in order to load and run it), but it is not used to assign "Initial directory".

'Hope that helps

Upvotes: 0

Ben Voigt
Ben Voigt

Reputation: 283803

Sort of.

There's one working directory, which is a complete path (including drive letter).

But there is a "current directory" for each drive, which affects drive-relative paths (of the form D:name with no backslash following the drive specification). IIRC, these are stored in the table of environment variables.

The link is that the shell automatically updates a current directory whenever the working directory changes. But other programs don't necessarily do this.

PATH search has no effect on current directory or working directory. They are inherited from the parent, unless explicitly specified when starting a new process.

See also this related question.

Upvotes: 1

Related Questions