why wrong file descriptor ??

This is a discussion on why wrong file descriptor ?? within the C Programming forums, part of the General Programming Boards category; hi friends,
its all code, but not getting why it is telling wrong descriptor.
Code:
1 //redirecting output of ls ...

> fd = open("tmp", O_CREAT|O_WRONLY
Both of them try and create a write_only file.
Unfortunately, one of them is expecting to be able to read the file.

Your understanding of fork() is fundamentally broken. Everything is asynchronous after you call a fork(), so it's quite easy for the "wc" to happen before the "ls" and for you to end up with a problem.