<div dir="ltr">Runxi,<div><br></div><div>Great question! I briefly went over this during Monday's lecture, although I'd be happy to go over it again!</div><div><br></div><div>When executing within the shell's child process:</div><div><ul><li>Upon success, `execlp()` will execute the provided program and `exit()` with its status code. If the program is executed successfully, the child process will exit prior to `fprintf()` being called. [0]</li><li>However; upon failure, `execlp()` will not exit the child process. Instead, the child process will continue executing and call the `fprintf()` error message.</li></ul><div>Please feel free to let me know if you have any additional/follow-up questions!<br></div></div><div><br></div><div><div>[0] <a href="http://linux.die.net/man/3/execlp">http://linux.die.net/man/3/execlp</a></div></div><div><br></div><div>Bests,</div><div>Patrick</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 1, 2016 at 11:02 AM, Runxi Ding <span dir="ltr"><<a href="mailto:rding6@stevens.edu" target="_blank">rding6@stevens.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I read source code of the simple_shell.c and found the following code:<div><br></div><div><div> /* child */</div><div> execlp(buf, buf, (char *)0);</div><div> fprintf(stderr, "shell: couldn't exec %s: %s\n", buf,</div><div> strerror(errno));</div><div> exit(EX_DATAERR);</div></div><div><br></div><div><br></div><div><b>Shouldn't the program print error every time? </b> The fact is that codes under execlp never get executed if execlp works properly.</div></div>
<br>______________________________<wbr>_________________<br>
cs631apue mailing list<br>
<a href="mailto:cs631apue@lists.stevens.edu">cs631apue@lists.stevens.edu</a><br>
<a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" rel="noreferrer" target="_blank">https://lists.stevens.edu/<wbr>mailman/listinfo/cs631apue</a><br>
<br></blockquote></div><br></div>