为什么exevp之前的printf没有运行?

and*_*ewg 4 c unix exec system-calls

我得到了"hi!"的输出.为什么这不打印"东西"?

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

int main(int argc, char** argv) {
    char* program_name = "echo";
    char* args[]= {program_name,"hi!",NULL};

    printf("something");
    execvp(program_name,args);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我知道我不是先创建一个子进程.如果我取出execvp行,它会按预期工作.奇怪的.(注意:"echo"是指https://en.wikipedia.org/wiki/Echo_(command))

Ed *_*eal 8

该字符串位于io缓冲区中 - 因此拉链并刷新该缓冲区

即添加

fflush(stdout)
Run Code Online (Sandbox Code Playgroud)

后的printf(或添加\nprintf)