LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2015, 04:48 AM   #1
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Rep: Reputation: Disabled
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.

Code:
1)
	read -p "Enter Memory Value [MB]" p 
	$script/simulate assignmem oxygen $p
	sleep 5
	;;

function assign_mem()
{ 
stop_kill $1
	ulimit -m $2 
"$script_folder"/"$1">/dev/null&
echo "Process $1 Assigned $2MB Memory"
}
 
Old 03-01-2015, 07:11 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Perhaps you could store the current amount in a variable.
 
Old 03-01-2015, 07:29 AM   #3
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Original Poster
Rep: Reputation: Disabled
what would the syntax for that be?
 
Old 03-01-2015, 07:52 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Code:
$ MEM=100
$ ADD=4
$ ((MEM += ADD))
$ echo $MEM
104
 
Old 03-01-2015, 09:28 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,633
Blog Entries: 4

Rep: Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931
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.
 
Old 03-01-2015, 09:53 AM   #6
rmcateer
Member
 
Registered: Oct 2014
Posts: 41

Original Poster
Rep: Reputation: Disabled
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
	;;
 
  


Reply

Tags
bash, memory, process, ubuntu 12.04, ulimit


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
In Linux, apart from malloc() what can increase the virtual memory of a process? gmwebway Programming 3 10-27-2010 09:37 AM
why is process's maximum virtual memory size limited to 1.2GB on PPC64 wagaboy Linux - Software 3 06-26-2010 06:50 AM
process, memory, swap, virtual memory wakatana Linux - Hardware 1 08-31-2009 07:55 AM
What memory is assigned to what program? qwertyjjj Linux - Server 21 08-07-2009 02:34 PM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 04:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration