Is into Lazarus 64 PC CPU usage and PC RAM usage Components for Linux lazarus / 32-Linux ---------------------------------------------------------------------- finalist · 2022-11-12 18:08 I am searching Components about 64 PC CPU usage and PC RAM usage example code for Linux. If there is that kind of components, I will install Lazarus 64 on my MX 21.2 Linux. Thanks ! ---------------------------------------------------------------------- Thaddy · 2022-11-12 20:25 You do not need a component for that (I highly recommend to not even look for it). In Unixes everything is a file, so:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program showcpuandmem;{$mode objfpc}{$h+}{$ifndef unix}{$error this is Unix flavors only}{$endif}uses classes;var  mem,cpu:TStrings; // this is a later edit, it read Tstringlist, but declaring it like this you can put the result in any Tstrings descendentbegin   mem := TStringlist.Create;  try    mem.LoadFromFile('/proc/meminfo'); // edit: contained a typo    writeln(mem.Text);  finally    mem.Free;  end;  cpu := TStringlist.Create;  try    cpu.LoadFromFile('/proc/cpuinfo');    writeln(cpu.Text);  finally    cpu.Free;  end;end.Is a simple example.....but it is the same logic as the higher level unix utilities use. The info is very verbose, so you may want to filter the data somewhat to your needs. And simply call this code periodically using a timer, a threadedtimer or OnIdle if you want near live updates. The code is so basic that it does not warrant a component. ---------------------------------------------------------------------- finalist · 2022-11-12 20:58 Quote from: Thaddy on November 12, 2022, 09:25:52 pmYou do not need a component for that (I highly recommend to not even look for it). In Unixes everything is a file, so:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program showcpuandmem;{$mode objfpc}{$h+}{$ifndef unix}{$error this is Unix flavors only}{$endif}uses classes;var  mem,cpu:TStringlist;begin   mem := TStringlist.Create;  try    mem.LoadFromFile('/proc/memifo');    writeln(mem.Text);  finally    mem.Free;  end;  cpu := TStringlist.Create;  try    cpu.LoadFromFile('/proc/cpuinfo');    writeln(cpu.Text);  finally    cpu.Free;  end;end.Is a simple example.....but it is the same logic as the higher level unix utilities use. The info is very verbose, so you may want to filter the data somewhat to your needs. And simply call this code periodically using a timer, a threadedtimer or OnIdle if you want near live updates. The code is so basic that it does not warrant a component. Thank You very much. I will transform above code may be into a function / procedure. I wil call that function / procedure periodically (500 ms or 1000 ms or .... ms ) ---------------------------------------------------------------------- MarkMLl · 2022-11-12 21:24 I'm in 100% agreement with Thaddy here, but I think one point is worth amplifying. Things that "look like files" in the /proc and /sys trees are actually generated on demand by the kernel, the special filesystems are just a convenient abstraction that allows kernel (and individual process) state to be queried. Back when Linux distreaux were somewhat less polished, it was possible to find oneself in an odd state where the kernel was running but /proc wasn't mounted. Because this was such an important interface to the kernel, when this happened utilities such as ps and top couldn't return any useful information. MarkMLl ---------------------------------------------------------------------- Thaddy · 2022-11-12 21:33 Tnx for explaining how it actually works, Mark. At 2: I know those days too ---------------------------------------------------------------------- MarkMLl · 2022-11-12 21:44 Quote from: Thaddy on November 12, 2022, 10:33:10 pmTnx for explaining how it actually works, Mark. At 2: I know those days too  :-) A lot of people assume that just because everything in unix looks like a file, it actually /is/ a file. On a typical system I'd estimate that there are thousands or tens of thousands of items in the /proc and /sys trees, and if the kernel really had to write every detail to a file a hundred or so times a second it would leave little if any time for anything else. Almost all the system state that utilities such as ps display come from those special filesystems. The rest comes from various sockets etc., into which application programs can- with care- tap. MarkMLl ---------------------------------------------------------------------- Thaddy · 2022-11-12 21:54 And the kernel "files" are extremely fast compared to other options for that reason. Anyway, @finalist should be able to write his own top clone by now ---------------------------------------------------------------------- finalist · 2022-11-12 22:34 Error:   Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Unable to open file "/proc/memifo": No such file or directory It is not so easy as it seems to be ... ---------------------------------------------------------------------- Thaddy · 2022-11-12 22:54 Quote from: finalist on November 12, 2022, 11:34:36 pmError:   Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Unable to open file "/proc/memifo": No such file or directory It is not so easy as it seems to be ... typo: should be meminfo, I editted the source accordingly. At home I already corrected this. Sorry for posting buggy code, but if you go back, you will see the edit. ---------------------------------------------------------------------- finalist · 2022-11-12 23:10 Thats fine: No more error ! Now have to find where are the results written .... ---------------------------------------------------------------------- finalist · 2022-11-12 23:25 Absolutely fantastic = it works  @Thaddy, thank You very much ! ---------------------------------------------------------------------- Thaddy · 2022-11-12 23:29 In my example to a terminal/console, but if you replace writeln with writestr you can write it to a string instead. See https://www.freepascal.org/docs-html/rtl/system/writestr.html ---------------------------------------------------------------------- finalist · 2022-11-12 23:31 Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MemTotal:      7992348 kBMemFree:         2064872 kBMemAvailable:    3792340 kBBuffers:          435644 kBCached:          2260764 kBSwapCached:     265592 kBActive:          2290260 kBInactive:        2990720 kBActive(anon):    1181992 kBInactive(anon):  2221476 kBActive(file):  1108268 kBInactive(file):   769244 kBUnevictable:      240136 kBMlocked:           17252 kBSwapTotal:       8104956 kBSwapFree:      7096060 kB Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i processor     : 0vendor_id       : GenuineIntelcpu family      : 6model         : 76model name      : Intel(R) Celeron(R) CPU  J3160  @ 1.60GHzstepping        : 4microcode       : 0x411cpu MHz         : 1635.400cache size      : 1024 KBphysical id     : 0siblings        : 4core id         : 0cpu cores       : 4apicid          : 0initial apicid  : 0fpu             : yesfpu_exception   : yescpuid level     : 11 ---------------------------------------------------------------------- Thaddy · 2022-11-13 09:07 Yup. Well done. See how simple that was? ---------------------------------------------------------------------- finalist · 2022-11-13 09:46 Yeah! Simple and fast working. I am happy, may be November the 13 is my happy day. Thanks again !