execlp睡眠不起作用

时间:2018-06-05 17:57:59

标签: c linux fork

如何让execlp()像系统一样工作(“睡5”)? 以下代码立即结束。

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;
}

0 个答案:

没有答案