I want to know that is this possible to code this program with using write(), read() functions. It takes 2 initial arguments with argv[] then fork() and after that child process' stdout passes to parents stdin and result will be showed on screen.

when I execute the program like this ---> ./program date wc

It must show a result as same as date | wc does in shell programming.

I coded this program with dup(). it works fine but I want to other way around. Thank you and sorry for my english.

I'm not clear quite what your problem is or what you're after. You should have close(fd[1]); in your child process code, and close(fd[0]); in your parent process code. You should also report an error and exit after each execvp(), just in case something goes wrong. You don't have to test the return value from execvp(); it only returns if there is an error. Other than those issues (which are fairly minor in this context, though they could be problematic in bigger contexts), your code looks good, though it is generally easier to use dup2() instead of close() plus dup() as shown.
–
Jonathan LefflerApr 16 '14 at 4:18