Advertisement
HAR1F

Untitled

May 23rd, 2020
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <fcntl.h>
  6. #include <limits.h>
  7.  
  8. int main()
  9. {
  10.     int fd[2];
  11.     if (pipe(fd) < 0)
  12.     {
  13.         exit(EXIT_FAILURE);
  14.     }
  15.     fcntl(fd[1], F_SETFL, O_NONBLOCK);
  16.     int bufs_count = 0;
  17.     char BUF[PIPE_BUF];
  18.     for(;;){
  19.         int bytes_write = write(fd[1], BUF, PIPE_BUF);
  20.         if(bytes_write < 1){
  21.             break;
  22.         }
  23.         bufs_count += 1;
  24.     }
  25.  
  26.     printf("pipe buffer size   : %d\n", PIPE_BUF);
  27.     printf("pipe buffers count : %d\n", bufs_count);
  28.     printf("default pipe size  : %d\n", bufs_count * PIPE_BUF);
  29.  
  30.     close(fd[0]);
  31.     close(fd[1]);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement