Problem with O_NONBLOCK Pipe

This is a discussion on Problem with O_NONBLOCK Pipe within the Linux Programming forums, part of the Platform Specific Boards category; Originally Posted by hosseinyounesi Another question: After closing my program, will the pipe file be deleted? I think no. So ...

  1. #16
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by hosseinyounesi View Post
    Another question: After closing my program, will the pipe file be deleted? I think no. So why?
    Because it's a named file you created. Remove it after you close the handle with unlink().
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #17
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    This is what I tried, and it is working now

    read:
    Code:
        fd_set rfds;
        int res=0;
        int retval;
        struct timeval tv;
        //////////////////
        FD_ZERO(&rfds);
        
        int pipe_fd = open( FIFO_NAME, O_RDONLY | O_NONBLOCK);
    
        FD_SET(pipe_fd, &rfds);
    
        tv.tv_sec = 1;
        tv.tv_usec = 0;
        int nfds = max( pipe_fd,1 ) + 1;
        retval = select(nfds, &rfds, NULL, NULL, &tv);
    
        if ( retval!=-1 )
        {
            if (FD_ISSET(pipe_fd,&rfds))
                res = read(pipe_fd, &T, sizeof(T));
        }
        close(pipe_fd);
    
        //Ignore Invalid Messages
        if(res != sizeof(T)) return -1;
    write:
    Code:
    int pipe_fd=0, res=0;
    //////////////////
    while(1)
    {    
        pipe_fd = open ( FIFO_NAME.c_str(), O_WRONLY );
        if ( pipe_fd == -1 )
              cout << "open error" << endl;
    
        res = write ( pipe_fd, &T, sizeof ( T ) );
        if ( res == -1 )
              cout << "write error" << endl;
    
        close ( pipe_fd );
        sleep ( 1 );
    }
    So, there is a select, controlling pipe with FD_ISSET and a sleep. If there is any AMBIGUITY or something is missed, please tell me.

    Thanks
    Last edited by hosseinyounesi; 09-18-2009 at 03:42 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pipe(): Interprocess or Intraprocess comm?
    By @nthony in forum C Programming
    Replies: 2
    Last Post: 03-28-2007, 08:27 PM
  2. Pipe problem, popen(), pipe().
    By apacz in forum C Programming
    Replies: 7
    Last Post: 06-08-2006, 01:55 AM
  3. named pipe problem
    By fnoyan in forum Linux Programming
    Replies: 0
    Last Post: 05-28-2006, 06:54 AM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21