如果我在一个线程中的chdir,那会影响父程序的cwd吗?

por*_*eux 3 c pthreads chdir

如果我在一个线程中的chdir,那会影响父程序的cwd吗?

Die*_*Epp 8

是.

如果在多线程应用程序中需要相对路径,则最安全的方法是使用at()函数版本.例如,openat()就像open():

int openat(int dirfd, const char *pathname, int flags);
Run Code Online (Sandbox Code Playgroud)

第一个参数是目录的fd.该路径相对于该目录.