gpt4 book ai didi

c - execlp() 系统调用输出错误

转载 作者:行者123 更新时间:2023-11-30 16:34:14 27 4
gpt4 key购买 nike

这是exec()系统调用的非常简单的示例。在这里,我尝试调用 execlp() 两次。但是,我没有得到异常(exception)的输出。它仅显示当前目录的第一次调用的输出。

#include <stdio.h>
#include <unistd.h>

int main() {

int ret1,ret2;
ret1 = execlp( "pwd", "pwd", (char *) 0);
ret2 = execlp( "date", "date", (char *) 0);
return 0;
}

输出:

/home/aniket

在这里,我看不到日期的输出。谁能解释一下为什么会发生这种情况?

最佳答案

execlp() 用新的进程镜像替换当前进程镜像。它不会返回(除非启动新进程时出现错误)。

因此,第二个 execlp() 调用永远不会到达。

关于c - execlp() 系统调用输出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49375634/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com