The point is this: I want to transfer cpu or gpu download data (for example, temperature) to linux (ubuntu 16.04) to a program on c \ c ++, but without using third-party utilities like lm sensors. Those. I want to extract data directly from the sensors (if possible) and transfer it to the program for further action, or somehow receive this data during the program operation. I saw a lot of answers about such actions using winapi, but under linux I didn’t find something (or overlooked it). And now, attention, question: mb someone faced this \ wrote something like this \ knows that google on this topic or even suddenly know how to implement it? Thanks in advance!
- see the lmsensors sources, everything is there, they turn to kernel modules that can write / read the "iron" port from the userspace, as far as I know, there will be no appeal to the iron ports. Here is a more correct answer unix.stackexchange.com/questions/42980/ ... - vasily-vm
- By the way, while waiting here for an answer, I rummaged through the English language stackoverflow and found a fairly well-formed code on the topic: github.com/spinlockirqsave/examples/blob/master/cpu/… - Shadr
1 answer
You will not receive this data directly from the sensors. The linux kernel will not allow the user application to access the hardware directly. In addition, you actually have to implement your own lm_sensors, because on different chipsets the data is obtained in different ways and in fact you need drivers for each specific sensor. There are already sensor drivers in linux and they are called lm_sensors (the nuclear part, not the utility). Please note that in windows in the same way, there are drivers in the kernel and there is a winapi interface.
In linux, you can get all the information from sensor drivers, as well as control some parameters (fan speed and limits) via the file interface /sys/class/hwmon and /sys/bus/platform/devices/coretemp.0 . Interface descriptions can be found in the file of kernel sources in the Documentation/hwmon/sysfs-interface .
Processor load can be calculated based on data from the /proc/stat file. A description of this interface can be found in the kernel source Documentation/filesystems/proc.txt .
- If reputation allowed me, I would vote for your answer :) But alas, I only registered today. - Shadr
- @Shadr, for a full-fledged level, you need to dial 300 (but you can already vote for 15 (see the list of privileges ) - avp
- @Mike, I searched here at the address you specified, but I only have a makefile there :) In general, the system does not have a proc.txt file, but in man the description of the interface, it turned out. They always talk about a certain time, and something tells me that it is on the basis of this "time" that it is - Shadr
- (I apologize, accidentally poked at the entr.) @Mike, I searched here at the address you specified, but I only have a makefile there :) In general, the system does not have a proc.txt file, but in man’s the description of the interface, it turned out. They always talk about a certain time, and something tells me that it is on the basis of this "time" that it is - Shadr
- In short, my hands are from my ass :) So, it seems to me that, based on this time, you can, as you say, calculate the load, but the level of knowledge does not even allow to estimate how this is done. Therefore, another question arose: maybe you know how it counts and you can share your experience or there is some kind of literature where you can quickly see it (so you don’t have to master a large amount of material for this) or, again, google it for me, because I don’t even know that in this case googling :) - Shadr