Buffer Lost To Exec
Compiled and run with stdout attached to a terminal, so stdio is line buffered.
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main(void) {
printf("A");
pid_t p = fork();
if (p == 0) {
printf("B");
execlp("echo", "echo", "C", (char *)NULL);
printf("D");
}
wait(NULL);
printf("E\n");
}
What appears on the terminal?
Sign in to answer questions and track your progress
Sign In