Find the answer to your Linux question:
Results 1 to 3 of 3
hi, I'm studying linux internals programming. can anyone tell me what is wrong in the following program? it hangs at the open statement.... I'm getting the "1" value which mkfifo ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    8

    Unhappy Help me with programming problem


    hi,

    I'm studying linux internals programming. can anyone tell me what is wrong in the following program? it hangs at the open statement.... I'm getting the "1" value which mkfifo returns...

    #include<stdio.h>
    #include<stdlib.h>
    #include<sys/types.h>
    #include<sys/stat.h>
    #include<unistd.h>
    #include<fcntl.h>
    int main()
    {
    int a,b=4,fid;
    printf("\n\n Hello World \n\n");
    a=mkfifo("new",0666);
    printf("\n mkfifo returnes : %d\n",a);
    fid=open("new",O_WRONLY,0777);
    printf("given number is : %d",b);
    write(fid,&b,sizeof(b));
    close(fid);
    return 0;
    }

  2. #2
    Just Joined!
    Join Date
    Aug 2011
    Posts
    51
    Try adding the flag O_NONBLOCK | O_WRONLY to the open call. Then it wont block on the open.

    man 2 open
    O_NONBLOCK or O_NDELAY
    When possible, the file is opened in non-blocking mode. Neither the open() nor any subsequent operations on the file descriptor which is returned will cause the calling process to wait. For the handling of FIFOs (named pipes), see also fifo(7). For a discussion of the effect of O_NONBLOCK in conjunction with mandatory file locks and with file leases, see fcntl(2).

    Out of a man fifo:
    A process can open a FIFO in non-blocking mode. In this case, opening for read only will succeed even if no-one has opened on the write side yet; opening for write only will fail with ENXIO (no such device or address) unless the other end has already been opened.

  3. #3
    Just Joined!
    Join Date
    Aug 2010
    Posts
    8

    Smile

    thanks... it's working now...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •