Process memory in Lua

How can I get meomory of any process in Lua?

Is this possible in Lua? Maybe C #, but I'm not sure.

In C #, we can use the PerformanceCounter class to get

PerformanceCounter WorkingSetMemoryCounter = new PerformanceCounter("Process", "Working Set", ReqProcess.ProcessName); 

What is equivalent to this in Lua?

Assume that there are 5 IE processes (Internet Explorer). How to get a list of these processes?

+1
source share
3 answers

To clarify what others have said, Lua is a scripting language designed for embedding. This means that it runs inside another application.

Lua.exe is one such application. But this is not the only application for which Lua scripts can be written to run.

Inside the Lua script, you have access to the exact and only what the application environment allows. If the application clearly does not allow you to access things like “files” or “operating system”, you cannot access them. Period.

The Lua standard library (which the application may forbid to use scripts. Lua.exe allows this, but there are some built-in environments that do not) are very few. It does not offer many of the amenities that make Lua ideal for embedded environments: small standard libraries mean smaller executables. That's why you see a lot more Lua in mobile applications than, say, Python. In addition, the standard library is cross-platform, so it does not have access to platform-specific libraries.

Modules, user programs (in Lua or C / C ++) can be loaded into the Lua.exe environment. Such a module can give your Lua script access to things like "processes", how much memory a process takes, etc. But if you do not have access to such a module, you do not get this information from the Lua script.

The most you can do is get the amount of memory that this Lua environment directly allocates and uses, as @lhf said: collectgarbage "count" .

+2
source

To get the memory allocated by Lua in Kbytes, use collectgarbage"count" .

+1
source

Lua does not come with this built-in functionality. You can write a binding to the library that provides this to you, or you could interact with a program for this (for example, read the output of "ps -aux | grep firefox").

0
source

Source: https://habr.com/ru/post/1432187/


All Articles