Using the exec() family to run the “cd” command

后端 未结 5 2057
醉酒成梦
醉酒成梦 2020-12-07 01:30

I know that cd is a shell built-in ,and I can run it by using system().

But is that possible to run the cd command by the

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 01:47

    When a fork is done the environment variable CWD(current working directory) is inherited by the child from the parent.If fork and exec is done as usual then the child calls chdir() which simply changes the directory to the new directory and exits but this does not affect the parent.Hence, the new environment is lost..

提交回复
热议问题