Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 970575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:49:39+00:00 2026-05-16T02:49:39+00:00

I have created a following program in which I wish to poll on the

  • 0

I have created a following program in which I wish to poll on the file descriptor of the file that I am opening in the program.

#define FILE "help"

int main()
{
        int ret1;
        struct pollfd  fds[1];

        ret1 =  open(FILE, O_CREAT);

        fds[0].fd = ret1;
        fds[0].events = POLLIN;

        while(1)
        {
                poll(fds,1,-1);

                if (fds[0].revents & POLLIN)
                        printf("POLLING");
        }
        return 0;
}

It is going in infinite loop. I am expecting to run the loop when some operation happen to the file. (Its a ASCII file)
plz help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:49:40+00:00Added an answer on May 16, 2026 at 2:49 am

    poll() actually doesn’t work on opened files. Since a read() on a file will never block, poll() will always return that you can read non-blocking from the file.

    This would (almost) work on character devices*, named pipes** or sockets, though, since those block when you read() from them when there is no data available. (you also need to actually read that data then, or else poll will tell again and again that data is available)

    To “poll” a growing/shrinking file, see man inotify or implement your own polling using fstat() in a loop.

    * block devices are a story apart; while technically a read from a harddisk can block for 10 ms or longer, this is not perceived as blocking I/O in linux.
    ** see also how to flush a named pipe using bash

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I have created UITableCellView class called NoteCell . The header defines the following: #import
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following code that creates two objects (ProfileManager and EmployerManager) where the
I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
I have created a C# Windows Forms application which I've attempted to make as
We have our custom setup.exe program which launches a series of individial MSIs in
I have created a .NET C# WinForms application on Win 7 RTM x64, which
My linux (SLES-8) server currently has glibc-2.2.5-235, but I have a program which won't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.