Linux管道通信问题

#求助!管道通信相关
#我用这段代码查询出来管道的缓冲区大小是4096字节,但是我循环写入一段字符串,明明总和超过了4096,为什么没有发生写阻塞呢?
但是当我把循环扩大到6000,就会阻塞

int main(){
    int fd[2];
    int ret;
    char writebuf[]="hello linux!";
    char readbuf[50]={0};
    char readbuf2[50]={0};
    ret=pipe(fd);
    if(ret<0)
    {
        printf("pipe creat failed!\n");
        return -1;
    }
    else
    {
        printf("pipe creat success!\n");
        printf("fd[0]=%d,fd[1]=%d\n",fd[0],fd[1]);
    }
    /*写阻塞*/
     int i=0;
     while (i<1000)
     {
        ret=write(fd[1],writebuf,sizeof(writebuf));
        i++;
     }
    
    ret=read(fd[0],readbuf,50);
    if(ret<0)
    {
        printf("pipe read failed!\n");
        return -1;
    }
    printf("pipe readbuf=%s\n",readbuf);
        // 使用 fpathconf 查询 PIPE_BUF,即管道的缓冲区大小
    long pipe_buf_size = fpathconf(fd[1], _PC_PIPE_BUF);
    if (pipe_buf_size == -1) {
        perror("fpathconf");
    } else {
        printf("Pipe buffer size: %ld bytes\n", pipe_buf_size);
    }
    // ret=read(fd[0],readbuf2,50);
    // printf("pipe readbuf2=%s\n",readbuf2);
    close(fd[0]);
    close(fd[1]);
    return 0;
}


【相关推荐】




如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^