How to Use Dprintf()

I've been told that the function dprintf() can be useful in writing data to pipes. Problem is, I can't find any examples that explain how to use it. I've read everything in that link, but still don't quite understand it.

Just a very simple example will help me understand a lot. For instance, 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 those pids to the pipe?

1 Answer

dprintf works just like fprintf, except the first parameter is a file descriptor (i.e. an int) instead of a FILE *.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest