how to change parent environment?

Felix Lee flee at cs.psu.edu
Fri May 3 21:36:21 AEST 1991


>How do you change the current working directory in a program, so
>that when the program is invoked from a shell, the cwd stays
>changed after the program exits?

Use ptrace().  In the child process you PTRACE_ATTACH the parent, save
the pc and registers and errno, find some spare room in the parent's
address space, write some code that will call chdir() and stop,
continue the parent at the code you've inserted, restore the pc and
registers and errno, and PTRACE_DETACH.

Implementation left as an exercise to the reader.
--
Felix Lee	flee at cs.psu.edu



More information about the Comp.unix.programmer mailing list