究竟是什么拥有“当前工作目录"? [英] Precisely what owns the 'current working directory'?

查看:170
本文介绍了究竟是什么拥有“当前工作目录"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道什么是工作目录(wd)及其用途(至少用于编写软件).

I'm aware what a working directory (wd) is and it's purpose (for writing software at least).

我不了解wd的所有权.此外,我想了解答案在不同的操作系统之间可能会如何变化,因此请您对特定操作系统上的不正常行为进行任何澄清.

What I don't understand is the ownership of the wd. Furthermore, I want to understand how the answer may vary between operating systems so any clarification on unusual behaviour on a particular OS would be appreciated.

因此,首先,WD在哪里显现?它是否在一个进程中,并且该进程创建的所有线程共享相同的wd?如果wd被线程"A"修改,则更改"B"立即可见,线程"B"也是由线程"A"产生的?

So firstly, where does the wd manifest itself? Is it within a process, and all threads created by that process share the same wd? If the wd gets modified by thread 'A', is the change instantly visible to thread 'B' which was also spawned by thread 'A's process?

其次,wd最初是如何定义的?如果您从命令提示符处启动某些命令,它的相当很容易理解,但是会产生更多进程的进程又如何呢?

And secondly, how is the wd initially defined? If you start something from a command prompt its fairly easy to see how, but what about a process which spawns several more processes?

注意:进程浏览器显示了其中每个进程的wd属性窗口.

Note: Process Explorer shows each process' wd in it's Properties window.

推荐答案

在大多数现代操作系统上,工作目录是进程的属性.当父进程派生子进程时,(默认情况下)它将具有相同的工作目录.通常可以通过显式指定工作目录来覆盖此行为.

On most modern operating systems, the working directory is a property of the process. When a parent process forks a child process, it will (by default) have the same working directory. This behaviour can usually be overriden by explicitly specifying a working directory.

一旦分叉,子级的工作目录字段将独立于父级.父级工作目录的更改不应更改子级进程.复制与工作目录相关的任何句柄或安全性令牌的行为在很大程度上取决于操作系统.

Once forked, the child's working directory field is independant of the parent. A change of the parent's working directory should not alter the child process. The behaviour of duplicating any handles or security tokens related to the working directory is highly dependant on the operating system.

在Windows上,CreateProcess RTL_USER_PROCESS_PARAMETERS 结构添加到进程的内存,其中包含UNICODE_STRING CurrentDirectoryPathHANDLE CurrentDirectoryHandle.在Windows的现有NT版本上,该结构始终加载在0x20000上,但是将来可能会更改.

On Windows, CreateProcess adds an RTL_USER_PROCESS_PARAMETERS structure to the memory of the process, which contains UNICODE_STRING CurrentDirectoryPath and HANDLE CurrentDirectoryHandle. The structure is always loaded at 0x20000 on existing NT versions of Windows, but this may change in future.

这篇关于究竟是什么拥有“当前工作目录"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆