0

How to make execlp() working like a system("sleep 5")?
Code below ends immediately.

int main()
{
        pid_t pid_child = fork();
        int status;
        if(pid_child == 0)
        {
                execlp("echo", "echo", "I will take a nap for a moment.", NULL);
                execlp("sleep", "sleep", "5", NULL);
                printf("Sleep has ended.\n");
        }
        else
        {
                wait(&status);
                printf("Parent out.");
        }

        return 0;
}
  • 1
    execlp only returns if it fails. Assuming your execlp of echo succeeded, your program will never get to the execlp of sleep. – rici Jun 05 '18 at 18:02
  • `exec` is not a standard function call, in case of success, you never return from it... S if the first `exec` succeed, the second one will never be executed. – Jean-Baptiste Yunès Jun 05 '18 at 18:02

0 Answers0