On enSO there are similar questions, but basically the answers are reduced, either to one of the OS, or to the use of system utilities on the command line in general.

The most appropriate of these answers to my task turned out to be this one , but it gives out the size of the borrowed process of the resident memory, while I would like to get the amount minus the shared one.

If you illustrate, then you need a value in the column "Memory":

Ubuntu System Monitor

It is possible that it is enough to somehow modify the example cited by the link above.

Addition

In view of the possible misunderstanding, I will supplement the question with an explanation of what is meant by the terms resident (RES) and shared (SHR) memory occupied by the process. This moment is detailed in detail on this site , but I will try to give an answer, as I understand it, in my own words with a simple example.

There are two text editors. Both processes use a kind of dynamically loaded library that performs spell checking. If one editor is launched for execution, then the size of the resident memory used by it will be that number of bytes, which is determined by its source code, plus the number of bytes, which is determined by the source code of the spelling check library. Similarly for the second text editor.

Thus, it is easy to understand that the same number of bytes occupied by the proficer spelling library will be included in the counters of the resident memory of one and the second text editor. The operating system will not place the library in memory in two identical instances, it will simply provide access to text editors for its address space. That is why the memory occupied by the library is called shared .

Finally, if you want to find out how much memory each of the text editors occupies without taking into account any auxiliary libraries, it suffices to subtract the value of the shared memory from the value of the resident memory.

The solution, based on spying the source code of command line utilities, is half-hearted, since it will obviously be difficult to do the same in Windows.

A good answer to the question could be an indication of specific system structures (for Windows and Linux) and a brief description of the flags, which will provide information about the size of shared memory occupied by the process.

It is not by chance that in the question I gave a link to the solution of the problem of obtaining the size of the resident memory cross-platform. It is likely that for the same structures it is sufficient to use just other flags. Unfortunately, due to a gap in the knowledge of system programming, I have not yet managed to solve this problem on my own, so I turned to ruSO in search of an answer.

Supplement 2

By "cross-platform" solution means the code for two different systems (Linux and Windows), but assembled in one place. That is, for external use, it is universal, while inside it is implemented for each platform independently:

#if defined(_WIN32) ... #elif defined(__unix__) || defined(__unix) || defined(unix) ... #endif 

Supplement 3

Judging by what is described in msdn , information relating to shared memory is either not provided at all or my analogy to the concept of shared memory between Linux and Windows is incorrect at all.

  • Comments are not intended for extended discussion; conversation moved to chat . - PashaPash

1 answer 1

https://pythonhosted.org/psutil is a great module, but on python. There you can see the source code as taken memory consumed by the process.

See proc.memory_info () and memory_full_info (). The latter has uss - so this is the one.

But resident and shared there, of course.