天天看点

linux中poll用法

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <stdio.h>

#include <poll.h>

int main(int argc, char **argv)

{

int fd;

   int ret; 

unsigned char key_val;

   struct pollfd *fds;

fd = open("/dev/buttons", O_RDWR);

if (fd < 0)

{

printf("can't open!\n");

}

   fds->fd = fd;

   fds->events =   POLLIN ;

while (1)

      ret = poll(fds, 1, 5000);

if(ret ==0)

      {printf("time out\n");

                   }

     else{

      read(fd, &key_val, 1);

printf("key_val = 0x%x\n", key_val);

                  }

}

return 0;

}