How to use dprintf ()

I was told that the dprintf () function can be useful when writing data to pipes. The problem is that I cannot find examples to explain how to use them. I read everything in this link, but still do not quite understand.

Just a very simple example will help me understand a lot. For example, if I had a pipe:

int fd[2]; pipe(fd); 

and a few pids

 pid_t ID1, ID2, ID3; 

How could I use dprintf () to write these pids to a pipe?

+5
source share
1 answer

dprintf works the same as fprintf , except that the first parameter is a file descriptor (i.e. int ) instead of FILE * .

 dprintf(fd[0], "%d : %d : %d", ID1, ID2, ID3); 
+7
source

All Articles