Getting Virtual Memory Max Map Count in Linux C++

1.7k views Asked by At

How to get 'sysctl vm.max_map_count', or the '/proc/sys/vm/max_map_count' using C++

I do not want to open the /proc/sys file.. Is there a http://man7.org/linux/man-pages/man2/sysctl.2.html call to get the number ?

1

There are 1 answers

1
Greg On

This sysctl command will return a key value pair.

sysctl -q vm.max_map_count
vm.max_map_count = xxxxxx

This sysctl command will return the same key value pair.

sysctl -e -q vm.max_map_count
vm.max_map_count = xxxxxx

This sysctl command will return the same key value pair.

sysctl -e -q vm.max_map_count
vm.max_map_count = xxxxxx

This sysctl command will return the same key value pair.

sysctl -n -e -q vm.max_map_count
xxxxxx

There is your answer. However, I would rather open /proc/sys/vm/max_map_count as a file and read the value verses executing a process from a C program. Calling sysctl in a bash script to set a variable would make more sense.

vmval=`sysctl -n -e -q vm.max_map_count`
echo $vmval
xxxxxx