Parallel programming and chaning directory

Earlier I used mostly languages that encouraged forking instead of threading so I am wondering. Do I understand correctly that "current working directory" is a per process feature and thus one cannot change to different directories in different threads?

What would be the recommended solution if I wanted to run code in parallel but each "stream" needs to change to its own directory? Shall I use fork ?

Just to give some more background, I need to run an external command on many folders and that command always works in the current directory.

Yes, this is correct.

I would fork for such a situation. There are obviously other ways to do it, but this is the sort of thing forking is really convenient for.

1 Like

When you run an external command using the std:: process module, then you can specify the current directory of the command. There's no need to change it for the Rust process.

5 Likes

current_dir
is probably the method you need.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.