小编Tex*_*xer的帖子

使用poll()检查文件修改

有一个文件,我想检查poll()内容已更改.

在Raspi上有一个名为gpio value的文件,如果更改的值poll()是用POLLPRI触发的,我想对普通文件做同样的事情.

这是我用来检查GPIO文件的代码:

int gpio_fd = gpio_fd_open();
int timeout = POLL_TIMEOUT;
struct pollfd fdset;
int nfds = 1;
char *buf[MAX_BUF];
int len;
int rc;
fdset.fd = gpio_fd;
fdset.events =  POLLPRI | POLLERR | POLLHUP | POLLNVAL; // POLLIN | | POLLOUT 
unsigned int c1, c2, c3;
do{
    rc = poll(&fdset, 1, timeout);
Run Code Online (Sandbox Code Playgroud)

和gpio_fd_open函数:

int gpio_fd_open() {
    printf("opening File: " SYSFS_GPIO_DIR "\n");

    int fd, len;
    char buf[MAX_BUF];

    len = snprintf(buf, sizeof (buf), SYSFS_GPIO_DIR);
    fd = open(buf, …
Run Code Online (Sandbox Code Playgroud)

c linux

7
推荐指数
1
解决办法
4028
查看次数

标签 统计

c ×1

linux ×1