You are not logged in.
Pages: 1
Recently,I am reading a book called <Linux For Programmers And Users>.Now I encounter a problem: As the
book states,when a user wanna execute a command or script,the subshell will be created,and the parent shell will sleep until the command or script is executed up.However,in my opinion,why should linux create a subshell to execute the command rather than we just execute that in parent shell?I think it will be easier.
I need your help,please.:)
Last edited by YZMSQ (2009-12-31 04:47:04)
This is the way the world ends
Not with a bang but a whimper
-------T·S·Eliot
Offline
If I remember correctly this is what happens:
- The parent shell forks (man 2 fork) and creates a new process that is a copy of itself.
- The new shell execs (man 2 execve) the binary or the script the user wanted to start. The exec replaces the code of the current process with the one of the program passed as argument to the system call.
If the parent shell would just exec the new process, there would not be a shell anymore !
You can try yourself, open a terminal and type 'exec ls' or something like that, this does exactly what you say. It wouldn't be so comfortable
Offline
Thank You For your help!
This is the way the world ends
Not with a bang but a whimper
-------T·S·Eliot
Offline
Pages: 1