title: What happens if you run 'exec ls' in your shell and why?
body: <p>The question is the title. I couldn't figure out why the terminal will shut down immediately after 'ls' is executed. A Linux shell is like this:</p>
  
  <blockquote>
    <p>1.while (1) {  <br/> 
    2. char *cmd = read_command();  <br/>
    3.  int child_pid = fork();  <br/>
    4.  if (child_pid == 0) {  <br/>
    5.    exec(cmd);  <br/>
    6.  }else {  <br/>
    7.    waitpid(child_pid);  <br/>
    8.  }  <br/>
    9.}  <br/></p>
  </blockquote>
  
  <p>So, if we run 'exec ls' in shell, cmd is a string of 'exec ls'. A child process is forked in line 3. In line 5, exec(cmd) will replace the child process but won't affect the father process. If the father process is not affected, why the terminal shuts down then?</p>
  
  <p>Please show me the flaws in my reasoning above.</p>