Sponsored Content
Top Forums Programming Getting the total virtual memory for ubuntu in c++ Post 302313388 by jim mcnamara on Tuesday 5th of May 2009 01:16:55 PM
Old 05-05-2009
pludi gave a fully correct answer. There are other ways involving accessing kernel memory directly, but that is very advanced programming.

You can also call popen() with a command of "vmstat -s".

This is the output of vmstat -s, you want the stuff in red
Code:
$ vmstat -s
      2096612  total memory
       788440  used memory 
            0  active memory
            0  inactive memory
      1308172  free memory
            0  buffer memory
            0  swap cache
      1572864  total swap
        13312  used swap
      1559552  free swap
     17632780 non-nice user cpu ticks
            0 nice user cpu ticks
     18800467 system cpu ticks
   1772277920 idle cpu ticks
            0 IO-wait cpu ticks
            0 IRQ cpu ticks
            0 softirq cpu ticks
     11051537 pages paged in
     22309640 pages paged out
     11051537 pages swapped in
       345219 pages swapped out
    481163032 interrupts
   1720440275 CPU context switches
   1240017420 boot time
            0 forks

It is easier to read the /proc/meminfo "file"
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Total Memory/Swap Memory

I need to put a program together to determine the total, available memory and total and available swap on unix machines. I have been searching for weeks and I seem to run into dead ends. Every unix platform I look at has a different way to determine memory info. Any sugggestions or new... (4 Replies)
Discussion started by: ghe1
4 Replies

2. Programming

about virtual memory and memory leak

Hi, First of all I appreciate this group very much for its informative discussions and posts. Here is my question. I have one process whose virtual memory size increases linearly from 6MB to 12MB in 20 minutes. Does that mean my process has memory leaks? In what cases does the... (4 Replies)
Discussion started by: shriashishpatil
4 Replies

3. UNIX for Dummies Questions & Answers

how can i get The total size of the process in virtual memory om GB or MB

Hello all im using the ps -ef "args vsz" | some.exe but the result is in kb , is there some kind of way or flag ( didnt found in the ps man ) to convert me this data to GB or MG in human readable format ? Thanks (1 Reply)
Discussion started by: umen
1 Replies

4. AIX

ulimits max locked memory virtual memory

Hi, Would any one be so kind to explain me : are ulimits defined for each user seperately ? When ? Specialy what is the impact of : max locked memory and virtual memory on performance of applications for a user. Many thanks. PS : this is what I can see in MAN : ulimit ] ... (5 Replies)
Discussion started by: big123456
5 Replies

5. UNIX for Dummies Questions & Answers

cpu, memory and virtual memory usage

Hi All, Does anyone know what the best commands in the UNIX command line are for obtaining this info: current CPU usage memory usage virtual memory usage preferably with date and time parameters too? thanks ocelot (4 Replies)
Discussion started by: ocelot
4 Replies

6. Solaris

How to find Total and Free Physical Memory and Logical Memory in SOLARIS 9

Hi, Im working on Solaris 9 on SPARC-32 bit running on an Ultra-80, and I have to find out the following:- 1. Total Physical Memory in the system(total RAM). 2. Available Physical Memory(i.e. RAM Usage) 3. Total (Logical) Memory in the system 4. Available (Logical) Memory. I know... (4 Replies)
Discussion started by: 0ktalmagik
4 Replies

7. Shell Programming and Scripting

Total usage memory by user

Hi, When running top on linux redhat machine , i see that i have 16gb of memory in my machine and about 14.5gb of memory are in use: Mem: 16395780k total, 14970960k used, 1424820k free, 370264k buffers Swap: 4192956k total, 25824k used, 4167132k free, 12029400k cached How can i... (3 Replies)
Discussion started by: yoavbe
3 Replies

8. Red Hat

Total Memory

Hi, I have a strange issue where the total memory on the server is showing low. At the moment 8 GB of memory is installed and only 3 GB is showing on the shell prompt. I am using the commands free -m and vmstat to check the memory. Please help me out in identifying the issue. With regards... (3 Replies)
Discussion started by: shabu
3 Replies

9. UNIX for Advanced & Expert Users

Finding out total memory usage

Hi, I have a server box with 16GB ram in it, within the server box there are 3 VMs running with a total allocation of 9GB. if I add up all the numbers under memory info using vmstat I get 15.8GB so I can say it adds up to 16Gb... Is there a way to see from the command line how much memory... (2 Replies)
Discussion started by: speedhunt3r
2 Replies

10. Shell Programming and Scripting

Calculate total memory using free -m

Hi I am trying to calculate memory used by Linux System free -m total used free shared buffers cached Mem: 32109 31010 1099 0 3600 7287 -/+ buffers/cache: 20121 11987 Swap: 10239 1282 8957 Now according to my requirement Im calculating memory using below cmd free -m | awk 'NR==3{printf... (2 Replies)
Discussion started by: sam@sam
2 Replies
VMSTAT(8)						       System Administration							 VMSTAT(8)

NAME
vmstat - Report virtual memory statistics SYNOPSIS
vmstat [options] [delay [count]] DESCRIPTION
vmstat reports information about processes, memory, paging, block IO, traps, disks and cpu activity. The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case. OPTIONS
delay The delay between updates in seconds. If no delay is specified, only one report is printed with the average values since boot. count Number of updates. In absence of count, when delay is defined, default is infinite. -a, --active Display active and inactive memory, given a 2.5.41 kernel or better. -f, --forks The -f switch displays the number of forks since boot. This includes the fork, vfork, and clone system calls, and is equivalent to the total number of tasks created. Each process is represented by one or more tasks, depending on thread usage. This display does not repeat. -m, --slabs Displays slabinfo. -n, --one-header Display the header only once rather than periodically. -s, --stats Displays a table of various event counters and memory statistics. This display does not repeat. -d, --disk Report disk statistics (2.5.70 or above required). -D, --disk-sum Report some summary statistics about disk activity. -p, --partition device Detailed statistics about partition (2.5.70 or above required). -S, --unit character Switches outputs between 1000 (k), 1024 (K), 1000000 (m), or 1048576 (M) bytes. Note this does not change the swap (si/so) or block (bi/bo) fields. -t, --timestamp Append timestamp to each line -w, --wide Wide output mode (useful for systems with higher amount of memory, where the default output mode suffers from unwanted column break- age). The output is wider than 80 characters per line. -V, --version Display version information and exit. -h, --help Display help and exit. FIELD DESCRIPTION FOR VM MODE
Procs r: The number of runnable processes (running or waiting for run time). b: The number of processes in uninterruptible sleep. Memory swpd: the amount of virtual memory used. free: the amount of idle memory. buff: the amount of memory used as buffers. cache: the amount of memory used as cache (excluding tmpfs memory for kernels 2.6.32+) inact: the amount of inactive memory. (-a option) active: the amount of active memory. (-a option) Swap si: Amount of memory swapped in from disk (/s). so: Amount of memory swapped to disk (/s). IO bi: Blocks received from a block device (blocks/s). bo: Blocks sent to a block device (blocks/s). System in: The number of interrupts per second, including the clock. cs: The number of context switches per second. CPU These are percentages of total CPU time. us: Time spent running non-kernel code. (user time, including nice time) sy: Time spent running kernel code. (system time) id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time. wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle. st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown. FIELD DESCRIPTION FOR DISK MODE
Reads total: Total reads completed successfully merged: grouped reads (resulting in one I/O) sectors: Sectors read successfully ms: milliseconds spent reading Writes total: Total writes completed successfully merged: grouped writes (resulting in one I/O) sectors: Sectors written successfully ms: milliseconds spent writing IO cur: I/O in progress s: seconds spent for I/O FIELD DESCRIPTION FOR DISK PARTITION MODE
reads: Total number of reads issued to this partition read sectors: Total read sectors for partition writes : Total number of writes issued to this partition requested writes: Total number of write requests made for partition FIELD DESCRIPTION FOR SLAB MODE
cache: Cache name num: Number of currently active objects total: Total number of available objects size: Size of each object pages: Number of pages with at least one active object NOTES
vmstat does not require special permissions. These reports are intended to help identify system bottlenecks. Linux vmstat does not count itself as a running process. All linux blocks are currently 1024 bytes. Old kernels may report blocks as 512 bytes, 2048 bytes, or 4096 bytes. Since procps 3.1.9, vmstat lets you choose units (k, K, m, M). Default is K (1024 bytes) in the default mode. vmstat uses slabinfo 1.1 FILES
/proc/meminfo /proc/stat /proc/*/stat SEE ALSO
free(1), iostat(1), mpstat(1), ps(1), sar(1), top(1) BUGS
Does not tabulate the block io per device or count the number of system calls. AUTHORS
Written by Henry Ware <al172@yfn.ysu.edu>. Fabian Frederick <ffrederick@users.sourceforge.net> (diskstat, slab, partitions...) REPORTING BUGS
Please send bug reports to <procps@freelists.org> procps-ng September 2011 VMSTAT(8)
All times are GMT -4. The time now is 04:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy