3 ms·
It's at the kernel level. Each process has its own current working directory. On Linux, these CWD values are exposed at `/proc/[...]/cwd`. This value affects th
by creatonez 10mo ago
It's at the kernel level. Each process has its own current working directory. On Linux, these CWD values are exposed at `/proc/[...]/cwd`. This value affects the resolution of relative paths in filesystem operations at a syscall level.
- hnlmorg 10mo agoIt’s also generally a shell builtin. Though you do find an executable called cd too for compatibility reasons.
- mattstir 10mo agoYeah, it's typically a shell built-in since you'd want cd to change the cwd for the shell process itself. Child processes (like commands being executed in the shell) can inherit the parent shell's cwd but AFAIK the opposite isn't true.
- deleted 10mo ago[deleted]
- jasomill 10mo agoInteresting. I've been using Unix systems for 30 years and never noticed this. On my Fedora system, /usr/bin/cd is just a shell script that invokes the shell builtin: #!/usr/bin/sh builtin cd "$@" I suppose it could be useful for testing whether a directory exists with search permissions for the current user safely in a multithreaded program that relies on the current directory remaining constant.
- creatonez 10mo agoWait, how did the `cd` executable used to work in old Unix? Did it instruct the kernel to reassign the CWD of the parent process?
- hnlmorg 10mo agoThe original UNIX shell (Thompson Shell) had chdir as a builtin, so I’d wager it’s always been a builtin. https://en.wikipedia.org/wiki/Thompson_shell https://en.wikipedia.org/wiki/Thompson_shell