echo "cd /" | sh
actually creates 2 new processes: echo, and sh. The sh process most probably does change the directory, but then just exits. You could test this by
echo "cd ../; touch Jimmix_was_here" | sh
ls -l ../Jimmix_was_here
which should show empty file Jimmix_was_here
file, with current timestamp (if you had write permission to the parent directory; otherwise the first command would throw error.)
There's no way to change current directory of a process from within a child; after all if it was possible, it would be a security hole!
Note: this reminds me of a seemingly paradoxical fact: why /bin/cd
exists?
Note 2: Try pstree | cat
and find both pstree and cat--they are siblings!