When a program accesses files, uses system()
, etc., how and where is the current working directory of that program physically known/stored? Since logically the working directory of a program is similar to a global variable, it should ideally be thread-local, especially in languages like D where "global" variables are thread-local by default. Would it be possible to make the current working directory of a program thread-local?
Note: If you are not familiar with D specifically, even a language-agnostic answer would be useful.
On Linux, each process is represented by a process descriptor - a task_struct
. This structure is defined in include/linux/sched.h in the kernel source.
One of the fields of task_struct
is a pointer to an fs_struct
, which stores filesystem-related information. fs_struct
is defined in include/linux/fs_struct.h.
fs_struct
has a field called pwd
, which stores information about the current working directory (the filesystem it is on, and the details of the directory itself).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With