为什么通过system()或execvp()从子进程调用cd shell命令不会工作?
问题描述:
我明白我应该使用chdir(),但我只需要一个解释,为什么通过系统或execvp()从子进程调用cd shell命令不会工作?感谢!!
I understand that i am supposed to use chdir() but I just need an explanation as to why calling cd shell command through system or execvp() from a child process would not work? Thanks!!
答
因为 chdir
只修改当前环境处理。它不能触及父级环境。
Because chdir
only modifies the environment of the current process. It can't touch the environment of the parent.
另请参阅链接。triee。
See also the link posted by tripleee.