Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a question regaridng pipes in c. for pipes, i know that you have an array

ID: 3729369 • Letter: I

Question

I have a question regaridng pipes in c.

for pipes, i know that you have an array of size 2. So,

int fd[2];

pipe(fd);

lets say i use dup2 for pipe, where stdin is read and stdout is write. what happens if I write to stdout multiple ints.

ie.

while (counter < 3){

write(stdout, counter, sizeof(int));

counter++;

}

will the pipe be an array of all the ints I wrote, or will the ints just be concatenated together, or etc. To simplify, the question is what is the format of the ints written to pipe.

Also, an explanation of how ints are read from pipes would be appreciated as well. Thanks

Explanation / Answer

Yes, the pipe is an array of all the ints.

Pipes send bytes from one place to another. So you need to precisely specify what bytes you are going to send. Then make sure your sending code sends precisely those bytes and your receiving code expects precisely those bytes.

the pipeline has an input end and an output end -- more than that doesn't make sense.

If you pass in anything larger than an int[2], the other slots will be unused.

This is how int is read from pipes:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote