Question 1 : Why is the directory where a program is installed not the initial directory of the process when running the program?
Actually, the installation path of a program is irrelevant. What matters is the current path of the father process. In case of a program launched from a shell, the father process is the shell itself so the initial current directory of the new process is the shell's current directory.
Question 2 : How can a process create a file outside from its current directory?
There are two ways to give the path of a file: absolute path and relative path. An absolute path is interpreted from the root of the filesystem (
/) and start with a slash ("/"). A relative path is interpreted from the current directory of the process. So if you have two directories, for example
/path2/path3, and a process whose current directory is
path2, it can open a file
path3/file. This path is relative (it doesn't start with a slash) so it's computed from the current directory
path2. And finally, the new file's complete path is
/path2/path3/file. So a process running in a given directory may create file outside of it.
Question 3 : How does the OS assign and change the current path for a process, during its running?
A process can ask the OS for changing its current directory by the mean of the
chdir(2) system call (provided that it has needed permissions on the new directory for it, etc. etc.). That's a different mechanism which has nothing to do with opening files. Opening files is done through another system call (namely