I am doing some experiments to know how environment variables are inherited from parent process to child process by executing shell scripts in zsh and then use pstree <username> to see the inheritance tree.
I suppose that zsh do a fork to run a script. But the process name in the pstree is the script file name not zsh.
#parent.sh
#! /bin/zsh
export AMA=1
./childEcho.sh #call child
#childEcho.sh
#! /bin/zsh
echo ${AMA}
./subchild.sh #call sub_child
#subchild.sh
#! /bin/zsh
echo ${AMA}
sleep 5d #sleep so that pstree can see the process tree
Then pstree shows that
sshd───zsh───parent.sh───childEcho.sh───subchild.sh───sleep
Then I delete the hashbang header in the scripts, run again and then by pstree, I will get
sshd───zsh───sh───sh───sh───sleep
So the process is now sh instead of the script file name.
- Why we have this different behavior?
- How pstree determines the process name and draws the tree?
- Something changed the process name at runtime?