gpt4 book ai didi

java - 用于 UNIX sys/classes/gpio 文件的 NIO watchservice

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:17:04 29 4
gpt4 key购买 nike

是否可以在 /sys/class/gpio/gpioX 设备树中的文件上设置 JAVA NIO WatchService 以监督那里的变化?

直接从 Java 中检测 GPIO 文件(即 GPIO 输入)的变化是个不错的主意,但我担心这不受支持。

确认它不受支持(可能还有原因)就足够了。

最佳答案

Java 7 NIO FileWatcher 的 linux 实现使用 inotify。 Inotify 是一个 linux 内核子系统,用于通知文件系统更改。它有限制并且不适用于/proc、/sys 和网络共享。请阅读inotify limitations on wiki :

Inotify does report some but not all events in sysfs and procfs.

Notification via inotify requires the kernel to be aware of all relevant filesystem events, which is not always possible for networked filesystems such as NFS where changes made by one client are not immediately broadcast to other clients.

还有一点:

inotify missing events
Java WatchService doesn't work on some folders
Java WatchService not generating events while watching mapped drives

关于java - 用于 UNIX sys/classes/gpio 文件的 NIO watchservice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30190730/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com