Page 1 of 1

How can a file's contents change but the file's attibutes remain the same?

Posted: 2022-01-25 19:44
by Yonut
I'm trying to write a system monitor for my desktop (no, I don't want to use something else), but I've come across a problem I can't understand.

I open the file `/sys/class/power_supply/BAT0/uevent` and notice all the fields. Close it and open it again and notice the field `POWER_SUPPLY_TEMP` value has changed from `315` to `318`. But when I do `ls /sys/class/power_supply/BAT0/uevent` it lists the modified date as the day I booted my system up (2 days prior).

How can the information in the file be updated but not have the attributes updated?

Also, why `inotify` isn't informed of a change to the file?

Re: How can a file's contents change but the file's attibutes remain the same?

Posted: 2022-01-25 19:54
by canci
Maybe the polling is so frequent that disk i/o or journaling would be compromised otherwise?

Re: How can a file's contents change but the file's attibutes remain the same?

Posted: 2022-01-25 19:57
by reinob
The stuff in /sys are not files. They just behave like files. The content is actually retrieved/calculated by the kernel *when you read*, while the "file" itself is created during boot, when /sys is mounted.

Re: How can a file's contents change but the file's attibutes remain the same?

Posted: 2022-01-25 20:13
by Yonut
Ty for the responses.

Looks like I'll have to make a `cron` job to copy the file regularly.