One obvious problem is that you do not write linefeeds to the pipe, which means that if anything in the whole string you write matches, grep
will output the whole string since it is only one line. Try adding a second write after the first:
write(pipe_fd[PIPE_WRITE],"\n",1);