see how much virtual memory is assigned to a process
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
see how much virtual memory is assigned to a process
I have written a script which assigns virtual or "simulated" memory to a process that I have created. What I want to know is, how can I then list how much memory the process has? I want it to return "process has x mbs" or "process has currently no assigned memory."
How can I do this? I have included snippets of the code as it is too long to do so for pasting in here.
Typically, if you want to find an accurate count of "how much memory a process has allocated or is using," you attach some form of instrumentation (or, use a library with instrumentation) to the malloc() and free() calls, or perhaps to some higher-level portion of the program which manages "interesting-to-you" data structures.
External measures of memory-use are only approximations. They generally can only see the "great big slabs of memory" (note: not using the Kernel term here ...) which the operating system hands to the program periodically for it to subdivide. They can't see how much of this the program considers to be "in use," nor what the program's using it for: only the program itself knows. Likewise, external agents can't readily see when a slab of memory is no longer being used for anything at all. Operating systems are designed to be "lazy," doing no overhead-work unless obliged to do so due to the presence of some external pressure. Thus, measurements taken on typical memory-glutted developer machines (which rarely if ever experience any sort of resource-pressure) are usually serious over-statements.
I have been trying to get it to read the memory that I have given it, which isn't real memory, but merely a simulation. When I put in this code, it just returns "display memory mbs." I want it to display the memory i assigned it with a previous function(if any) and i know it should be simple, but I am missing something-what is it? This is my code attempt:
Code:
function display_memory()
{
"$script_folder"/"$1">/dev/null&
echo $2MB
echo "Process $1 currently assigned $2MB Memory"
}
and from the menu
Code:
1)
read -p "display Memory Value [MB]" p
$script/simulate displaymemory oxygen $p
sleep 5
;;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.