[cs631apue] how execlp works?

Patrick Murray pmurray1 at stevens.edu
Thu Sep 1 13:27:01 EDT 2016


Runxi,

Great question! I briefly went over this during Monday's lecture, although
I'd be happy to go over it again!

When executing within the shell's child process:

   - 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]
   - However; upon failure, `execlp()` will not exit the child process.
   Instead, the child process will continue executing and call the `fprintf()`
   error message.

Please feel free to let me know if you have any additional/follow-up
questions!

[0] http://linux.die.net/man/3/execlp

Bests,
Patrick

On Thu, Sep 1, 2016 at 11:02 AM, Runxi Ding <rding6 at stevens.edu> wrote:

> I read source code of the simple_shell.c and found the following code:
>
>               /* child */
>               execlp(buf, buf, (char *)0);
>               fprintf(stderr, "shell: couldn't exec %s: %s\n", buf,
>                       strerror(errno));
>               exit(EX_DATAERR);
>
>
> *Shouldn't the program print error every time? * The fact is that codes
> under execlp never get executed if execlp works properly.
>
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20160901/c3f27aa1/attachment.html>


More information about the cs631apue mailing list