LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-07-2012, 12:25 AM   #1
nagendrar
Member
 
Registered: Apr 2008
Location: HYD, INDIA.
Posts: 154

Rep: Reputation: 15
Problem in select() with open() fd


I want to return from select() whenever file was modified.

I wrote following way but select is returning continuously even tough file was not modified.

Please help me to solve this problem


Code:
#include <sys/time.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/select.h>

int main(){

        char filepath[1024];
        memset(filepath,0,1024);
        strcpy(filepath,"/home/test/abc.log");
        int fd;
        fd_set select_list;
        FD_ZERO(&select_list);
        fd = open (filepath,O_RDONLY);
        if ( fd > 0 ) {
                if ( FD_ISSET( fd, &select_list ))
                        FD_CLR( fd, &select_list );

                FD_SET( fd, &select_list );
                printf("Added %s File for Stream watch,%d\n", filepath,fd);
        }
        else {
                printf("Failed to add the file %s to stream list,Error:%s\n",filepath,strerror(errno));
        }
        while(1)
        {
                printf("==============1\n");
                int bReady = select( fd+1, &select_list, NULL, NULL, NULL );
                printf("==============2:%d\n",bReady);
                if(bReady <= 0)
                {
                        continue;
                        sleep(15);
                }
                printf("==========3:%d\n",bReady);
                sleep(2);
        }

}

ThanQ,
Nagendra
 
Old 03-07-2012, 07:46 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
select(2) is not meant to use for disk-files, but sockets, pipes, character devices...
Perhaps inotify(7) would help
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Application select for firefox "open folder containing" Jeff91 Linux - Software 1 07-07-2009 01:14 PM
select problem Marrti Jokinen Linux - Newbie 1 06-12-2009 04:47 AM
Problem select( ) teqno82 Programming 1 06-02-2006 05:59 AM
problem with select() fnoyan Programming 3 12-21-2005 03:17 PM
auto select open in forms? @ngelot Programming 1 05-11-2005 05:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration