What is actually changing the directory? – technical discussion

Ten minutes ago an idea popped into my mind and I’m bored on my phone (and not laptop). When I do an os.Chdir(“…/”) , what is actually changing the directory? Is this the goroutine for which the function was called? Is it the entire executable? If I start a goroutine, change to a different directory, then call Getcwd from the main goroutine, will it call the original dir or the new one?

It is easy to test.
func os.Chdir is applied to the whole process, main and other groutins are alive and in progress, so it calls new dir

1 like

Leave a Comment