I'm trying to get a feeling about how pipe works in Linux. I wrote the following program, compiled it and then run it in terminal. The program exits normally without errors, but it didn't print out any message. Is there anything wrong?
PS: this code snippet is from MIT's xv6 operating system course.
#include <stdio.h>
#include <unistd.h>
int main() {
int p[2];
char *argv[2];
argv[0] = "wc";
argv[1] = 0;
pipe(p);
if (fork() == 0) {
close(0);
dup(p[0]);
close(p[0]);
close(p[1]);
execvp("/bin/wc", argv);
} else {
write(p[1], "hello world\n", 12);
close(p[0]);
close(p[1]);
}
}