Thursday, September 22, 2011

In C how can i make a forked process that have the same working directory as its parent?

I know they always start at the same directory but i want the parent to change its wd as the children does.



(somthing like that : ... if (0==fork()) { execlp(';cd';,';...';,0 ) } else { parent with changed wd } )In C how can i make a forked process that have the same working directory as its parent?
There's no automatic way to do what you want.



You could do this by doing the following:



1) Open a pipe before you fork (closing the right ends in the parent and child)

2) Use the chdir() system call in the child

3) Write to the pipe then the chdir() succeeds (in the child process).

4) In the parent, read the pipe to get the new directory and use chdir().
  • Parameter.Add()
  • virtual barber shop
  • No comments:

    Post a Comment