If I chdir within a thread, will that affect the cwd of the parent program?

c, chdir, pthreads

Solution

Yes.

If you need relative paths in a multithreaded application, it's safest to use the `at()` versions of functions. For example, `openat()` is like `open()`:

int openat(int dirfd, const char *pathname, int flags);

The first parameter is the fd to a directory. The path is relative to that directory.

Problem

If I chdir within a thread, will that affect the cwd of the parent program?

Original source