How do 2 processes communicate by using single bidirectional pipe, such that both the ends of the pipe could read and write.
You don't. Pipes are unidirectional: you write at the write end, and read from the read end.
If you want bidirectional communication, use a socket, or two pipes.
You can use a pipe for bidirectional communication if both processes keep both ends of the pipe open. You need to define a protocol for whose turn it is to talk. This is highly impractical.