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 program which allows a user to guess a word
I have created following rule in the .htaccess file located at the root of
I have created the following vsct file xml. <?xml version=1.0 encoding=utf-8?> <CommandTable xmlns=http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable xmlns:xs=http://www.w3.org/2001/XMLSchema>
In Java I have created the following class which extends ImageView to create a
I have a header-file, the COM interface. I have created a small win32 program
I have created some application, which is reading from System.in using the following method:
I have created a visual studio 2010 solution from the following .pro file: TEMPLATE
I have a java program which does individual jobs e.g. takes in a file,
I have created a class-managed GUI in which the following methods are defined function
I have created following thing in android using android compatibility support package Basically i

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.