yungweezy
yungweezy

Reputation: 39

Lines above execv() don't run?

Working on some dups of pipes and was trying to test my program. I tried to print something before execv() and i realised the print doesn't run. Is this normal?

if (pid == 0) {
    printf("hi"); // <- does not run
            
    execv(singleProcess[0], (char *const *) singleProcess);
}

Upvotes: 0

Views: 69

Answers (1)

Ingo Leonhardt
Ingo Leonhardt

Reputation: 9894

printf() is called. But the output will most probably be buffered and the stdio-buffer is not flushed when the process is replaced by execv().

Normally stdout is line buffered and you don't write a Newline. But anyway as long as you don't explicitely set it, I wouldn't rely on any specfic buffering mode.

Just call fflush(stdout); after printf() and before execv() and you will see the output.

Upvotes: 2

Related Questions