Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^13: Controlling USB on Raspberry Pi

by afoken (Canon)
on Dec 13, 2020 at 16:10 UTC ( #11125113=note: print w/replies, xml ) Need Help??

in reply to Re^12: Controlling USB on Raspberry Pi
in thread Controlling USB on Raspberry Pi

The files in /sys/ are actually kernel drivers, much like in /proc/. Those file-based drivers are rather simple-minded and desigend to use by shell scripts, where each echo foo > /proc/some/magic/file ends in calling open(2), write(2), and close(2). So you should simulate that behaviour.

I completely forgot to mention that perl and/or the C library try to AVOID writing files, because writing files is slow (compared to writing to RAM). So, there is at least one layer of caching between your program and the kernel drivers. That cache needs to be flushed for the kernel drivers to see your program writing to the virtual files. Simply closing the file handle is the easiest way to do that. $| (autoflush) would probably also work. But as shown, just closing the file also avoids having unused file handles lingering around.


Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125113]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2022-08-18 01:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found