小编ani*_*tar的帖子

调用execv之后的怪异行为

我正在尝试使用execv执行命令。运行该程序后,我可以看到“将要调用execv!”语句。在标准输出上打印。

我还可以从程序“ leaky”中看到打印内容。实际上,一切都按预期工作,除了在if或else块中看不到打印语句外,即“ execv failed!error:”和“ Valgrind成功执行!” 在输出上打印。

我在这里是否缺少关于execv的明显要点?

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

int main()
{
   char *args[5] = {"/usr/bin/valgrind", "--leak-check=full", "--log-file=valgrindReport.txt", "./leaky", NULL};
   printf("Going to call execv!\n");
   if(execv("/usr/bin/valgrind", args) < 0)
   {
      printf("execv failed! error: %s\n", strerror(errno));
      return 0;
   }
   else
   {
      printf("Successfully executed valgrind!\n");
   }
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

c linux execv

2
推荐指数
1
解决办法
244
查看次数

标签 统计

c ×1

execv ×1

linux ×1