exec() Without fork()
Question Text
We type the following command:
student@os:~$ ls
Why does the shell NOT simply call exec("/bin/ls")?
Question Answers
- Because
/bin/lsmay be buggy or vulnerable and compromise the shell
- Because when
lsends, the shell is closed
Because the
lsandbashprocesses must not share the same address spaceBecause
bashneeds to pass data to thelsprocess
Feedback
If the shell simply execs "/bin/ls", the bash process is entirely replaced by the ls process.
Therefore, when the ls process ends, the old bash process is no more and the terminal closes.
This way, each command would close the terminal.