linux - chdir system call in C program -
this question has answer here:
program:
#include<stdio.h> #include<unistd.h> int main() { char s[100]; printf("%s\n",getcwd(s,100)); chdir(".."); printf("%s\n",getcwd(s,100)); return 0; }
output:
$ ./a.out /home/guest /home $
the above program changes working directory of process. but, doesn't change working directory of current shell. because when program executed in shell, shell follows fork on exec mechanism. so, doesn't affect current shell.
is there way change current working directory of shell via these program built-in (cd, echo) command used shell?
is there way change current working directory of shell via these program buildin(cd,echo) command used shell.
you can't that.
allowing child process change current directory, or state matter, of parent process wreak havoc on parent process.
Comments
Post a Comment