Reputation: 349
Consider this code of prog.c:
#include <sys/time.h>
#include <stdio.h>
#define SIZE 10000
int main(){
char buffer[SIZE];
int pipefd[2];
pipe(pipefd);
while (1){
write(pipefd[1], buffer, SIZE);
read(pipefd[0], buffer, SIZE);
}
return 0;
}
When i run it in a bash with the following:
time ./prog
The output would be:
real 0m2.672s
user 0m0.693s
sys 0m1.978s
As you can see user time + sys time = (approximately) real time.
And here I'm wondering, why doesn't the reading and writing into a pipe take I/O time which would manifest by a real time much bigger than the sum of user and sys times.
Upvotes: 1
Views: 116
Reputation: 349
With the help of the comment section, it appears that the write/read are done in buffer corresponding to the pipe itself, there is no actual read/write into an I/O device.
This copy/past of buffer zone is done by syscall write/read where the kernel spend it time coping from the buffer of variable to the buffer of the pipe.
That's why the sum of user and sys time are the actual real time.
Upvotes: 1