进程的当前目录是否等于其工作目录?

时间:2022-10-30 22:42:19

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?

当我在PATH搜索文件夹下启动程序时,第一个文件夹会成为其当前目录吗?

3 个解决方案

#1


1  

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.

但是每个驱动器都有一个“当前目录”,它会影响驱动器相对路径(D形式:驱动器规范后没有反斜杠的名称)。 IIRC,这些存储在环境变量表中。

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

链接是每当工作目录更改时,shell会自动更新当前目录。但其他程序并不一定如此。

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.

PATH搜索对当前目录或工作目录没有影响。它们是从父级继承的,除非在启动新进程时明确指定。

See also this related question.

另请参阅此相关问题。

#2


0  

"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:

AFAIK,“当前目录”,“当前工作目录”和“工作目录”都是完全相同的同义词。他们当然是在Linux,Java(可以说是.Net)的土地上。但是,在Windows中,进程可以为每个驱动器使用不同的“工作目录”:

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

    .exe所在的目录(如果从Windows资源管理器中双击它),或

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

    桌面链接指定的目录(如果双击Windows快捷方式)

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

换句话说,“初始目录”和“exe所在的目录”可以相同或不同。

  • 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".

该路径有助于OS找到.exe(为了加载和运行它),但它不用于分配“初始目录”。

'Hope that helps

'希望有所帮助

#3


0  

"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).

(我的链接是.net相关的,可能不是您选择的技术)。

#1


1  

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.

但是每个驱动器都有一个“当前目录”,它会影响驱动器相对路径(D形式:驱动器规范后没有反斜杠的名称)。 IIRC,这些存储在环境变量表中。

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

链接是每当工作目录更改时,shell会自动更新当前目录。但其他程序并不一定如此。

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.

PATH搜索对当前目录或工作目录没有影响。它们是从父级继承的,除非在启动新进程时明确指定。

See also this related question.

另请参阅此相关问题。

#2


0  

"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:

AFAIK,“当前目录”,“当前工作目录”和“工作目录”都是完全相同的同义词。他们当然是在Linux,Java(可以说是.Net)的土地上。但是,在Windows中,进程可以为每个驱动器使用不同的“工作目录”:

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

    .exe所在的目录(如果从Windows资源管理器中双击它),或

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

    桌面链接指定的目录(如果双击Windows快捷方式)

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

换句话说,“初始目录”和“exe所在的目录”可以相同或不同。

  • 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".

该路径有助于OS找到.exe(为了加载和运行它),但它不用于分配“初始目录”。

'Hope that helps

'希望有所帮助

#3


0  

"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).

(我的链接是.net相关的,可能不是您选择的技术)。