The non blocking read pipe end still show pipe is full even when i send a message

What i want to do with the program is to create 3 child processes from one parent . Each child will have 2 pipes connecting to the parent so it can write to the parent and read from it. With this i want the children to communicate with each other trough the parent for example child 1 decides to send a message to child 3 it will first send to the parent then the parent will send it to child 3. To do that i need to make the read pipe ends non blocking. When no massage has been send it works fine but when i try to send something it still writes that pipe is full. My questions is what i am doing wrong?

The example i am following is from this site https://www.geeksforgeeks.org/non-blocking-io-with-pipes-in-c/ . Note that my code is nowhere near finished . I still have a lot of work but i have been stuck on the non blocking. The write at child A near the end is just a test to see if it will send it.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
    int pids[3],id[3];
    int pipes[6][2];
    int i;
    for (i=0;i<6;i++)//Creating the pipes
    {
        if (pipe(pipes[i])==-1)
        {
            printf("Error in pipe %dn",i);
            return 0;
        }
        else
        {
            printf("Pipe created!n");
        }
    }



    for(i=0;i<6;i++)//Here i call fcntl for all the pipes
    {
        if (fcntl(pipes[i][0],F_SETFL,O_NONBLOCK)<0)
        {
            printf("Error in fcntl:%d",i);
        }
    }



    for(i=0;i<3;i++)//Store child process id on array
    {
        pids[i]=fork();

        if(pids[i]==0)
        {
            id[i]=getpid();
             break;
        }
    }



    if (getpid()==id[0])//Close pipes that are no neede in child A it keeps 0 and 1
        {
            for (i=0;i<6;i++)
            {
                if (i>0 && i>1)
                {
                    close(pipes[i][0]);
                    close(pipes[i][1]);
                    printf("Ola kala sto klisimo sto A:%dn",i);
                }
            }
            close(pipes[0][1]);
            close(pipes[1][0]);
            return 0;
        }



    if (getpid()==id[1])//Close pipes that are no neede in child B it keeps 2 and 3
        {
            for (i=0;i<6;i++)
            {
                if ((i>2 && i>3) || (i<2 && i<3))
                {
                    close(pipes[i][0]);
                    close(pipes[i][1]);
                    printf("Ola kala sto klisimo sto B:%dn",i);
                }
            }
            close(pipes[2][1]);
            close(pipes[3][0]);
            return 0;
        }



    if (getpid()==id[2])//Close pipes that are no neede in child C it keeps 4 and 5
        {
             for (i=0;i<6;i++)
            {
                if (i<4 && i<5)
                {
                    close(pipes[i][0]);
                    close(pipes[i][1]);
                    printf("Pipe has close in C:%dn",i);
                }
            }
            close(pipes[4][1]);
            close(pipes[5][0]);
            return 0;
        }



    if (getpid()==id[0])//Child A trys to send a massage
    {
       int l=4;
       write(pipes[0][1], &l,sizeof(int));
    }
    if(getpid()!=0)
    {
        sleep(3);
        int nread,buf;
        nread = read(pipes[0][0], &buf, sizeof(int));
        switch (nread) {
        case -1:

            // case -1 means pipe is empty and errono
            // set EAGAIN
            if (errno == EAGAIN) {
                printf("(pipe empty)n");
                sleep(1);
                break;
            }

            else {
                perror("read");
                exit(4);
            }

        // case 0 means all bytes are read and EOF(end of conv.)
        case 0:
            printf("End of conversationn");

            // read link
            close(pipes[0][0]);

            exit(0);
        default:

            // text read
            // by default return no. of bytes
            // which read call read at that time
            printf("MSG = %dn", buf);
        }
    }


    if(getpid()!=0)//The perent waits for all the children
    {

        for(i=0;i<=3;i++)
        {
            wait(NULL);

        }
        printf("PARENT:%dn",getpid());
    }
}

The example i am following is from this site https://www.geeksforgeeks.org/non-blocking-io-with-pipes-in-c/ .Note that my code is nowhere near finished . I still have a lot of work but i have been stuck on the non blocking. The write at child A near the end is just a test to see if it will send it.

New contributor

Niko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật