Skip to content
Advertisement

Reading Long Values From Sysfs Path With Escape Characters

I am using C file IO to read value from a sysfs interface in linux. Path and sample value of the register is as follows:

JavaScript

Code: Added after intel-rapl to take into account unknown escape sequence

JavaScript

The code compiles without any error, but in the output file I am getting value as 0. Is this due to how I am taking into account the escape sequence?

Thanks.

Advertisement

Answer

Since the sysfs files, while ‘files’ in one sense, may also be nodes, etc.. and not traditional text files, it is often best to let the shell interact with the sysfs files and simply read the needed values from a pipe following a call to popen using the shell command, e.g.

JavaScript

Example Use/Output

JavaScript

That’s not to say you cannot read from the sysfs files directly, but if you have any problems, then reading from a pipe is fine. For the energy_uj value, it can be read directly without issue:

JavaScript

Example Use/Output

JavaScript
Advertisement