poll.2 (2010 09)

p
poll(2) poll(2)
fds.fd = 0;
fds.events = POLLNORM;
poll(&fds, 1, -1);
Wait for input on ifd1
and ifd2, output on ofd, giving up after 10 seconds:
#include <poll.h>
struct pollfd fds[3];
int ifd1, ifd2, ofd, count;
fds[0].fd = ifd1;
fds[0].events = POLLNORM;
fds[1].fd = ifd2;
fds[1].events = POLLNORM;
fds[2].fd = ofd;
fds[2].events = POLLOUT;
count = poll(fds, 3, 10000);
if (count == -1) {
perror("poll failed");
exit(1);
}
if (count==0)
printf("No data for reading or writing\n");
if (fds[0].revents & POLLNORM)
printf("There is data for reading fd %d\n", fds[0].fd);
if (fds[1].revents & POLLNORM)
printf("There is data for reading fd %d\n", fds[1].fd);
if (fds[2].revents & POLLOUT)
printf("There is room to write on fd %d\n", fds[2].fd);
Check for input or output on file descriptor 5 without waiting:
#include <poll.h>
struct pollfd fds;
fds.fd = 5;
fds.events = POLLNORM|POLLOUT;
poll(&fds, 1, 0);
if (fds.revents & POLLNORM)
printf("There is data available on fd %d\n", fds.fd);
if (fds.revents & POLLOUT)
printf("There is room to write on fd %d\n", fds.fd);
Wait 3.5 seconds:
#include <stdio.h>
#include <poll.h>
poll((struct pollfd *) NULL, 0, 3500);
Wait for a high priority, priority, or normal message on streams file descriptor 0:
#include <poll.h>
struct pollfd fds;
fds.fd = 0;
fds.events = POLLIN|POLLPRI;
poll(&fds, 1, -1);
SEE ALSO
read(2), write(2), select(2), getmsg(2), putmsg(2), streamio(7).
STANDARDS CONFORMANCE
poll(): AES, SVID2, SVID3
HP-UX 11i Version 3: September 2010 3 Hewlett-Packard Company 3