C
C
ctacka2017-01-09 17:37:36
linux
ctacka, 2017-01-09 17:37:36

How is the current directory stored in linux?

  • how is the current directory stored in linux?
  • how does the cd command (not the result, but the process) work?
  • how can i change the current directory other than cd?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
C
ctacka, 2017-01-09
@ctacka

/proc/$$/cwd is a symlink to the current directory

J
jcmvbkbc, 2017-01-09
@jcmvbkbc

how is the current directory stored in linux?

The current directory is an attribute of each process. It is stored in the task_struct structure , in the fs->pwd field as an object of type path. The kernel provides the following interface to the current directory:
int chdir(const char *path);
char *getcwd(char *buf, size_t size);

Makes the chdir system call. This is easy to observe with strace:
$ strace bash -c "cd /" 2>&1 | grep chdir
chdir("/")                              = 0

G
GavriKos, 2017-01-09
@GavriKos

how is the current directory stored in linux?

Somewhere in the depths of the process memory that knows about the current directory. Most likely bash.
The sources are most likely open - take it and see.

M
Max, 2017-01-09
@MaxDukov

stored in environment variables, in PWD variable
except for cd, set great via PWD="/"

A
Alexander Morgunov, 2017-06-27
@AleksKek

This is done most correctly like this https://jsfiddle.net/0f9v8p6h/.

N
Niriter Inc., 2017-06-27
@niriter

CSS ONLY!!!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question