execlp() 系统调用错误输出 [英] execlp() system call error in output

查看:42
本文介绍了execlp() 系统调用错误输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This very simple example of exec() system call. Here, I am trying to call execlp() twice. But, I am not getting excepted output. It shows output only for first call with current directory.

#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

在这里,我看不到日期的输出.谁能解释一下为什么会这样?

Here, I can't see output for date. Can anyone please explain why is this happening?

推荐答案

execlp() 用新的过程映像替换当前的过程映像.它不返回(除非启动新进程时出错).

execlp() replaces the current process image with a new process image. It does not return (unless there was an error starting the new process).

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

Therefore the second execlp() call is never reached.

这篇关于execlp() 系统调用错误输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆