Unix - How do I use poll()?

How do I use poll()?

Poll() in UNIX is used for to wait for some event on a file descriptor. When poll() is used, the user must allocate an array of pollfd structures, and pass the number of entries in this array.
int poll(struct pollfd *ufds, unsigned int nfds, int timeout)

The parameter fd is a file descriptor to open the file while timeout is in milliseconds. If the timeout value is negative, it means negative timeout. The structure if the is as below:
struct pollfd {
        int fd; /* file descriptor */
        short events; /* requested events */
        short revents; /* returned events */
};

How do I use poll()?

poll() allows an event to wait on a file descriptor. A pointer is accepted by poll() to a list of ‘struct pollfd’. A bitwise mask is used to specify the events in the field of events of the structure. The structure’s instance will be filled at a later point of time and returns with events that were occurred.

The struct pollfd has the following format
struct pollfd {
        int fd; /* The descriptor. */
        short events; /* The event(s) is/are specified here. */
        short revents; /* Events found are returned here. */
};
What is a compiler? - operating system
A compiler is a program that takes a source code as an input and converts it into an object code......
Loader and linker - operating system
A loader is a program used by an operating system to load programs from a secondary to main memory so as to be executed......
Types of memory - operating system
The basic types of memories that a computer has are: RAM Random access memory, ROM Read Only memory.....
Post your comment