1

I'm using Fedora release 17 (Beefy Miracle) in my lab, i trying to block 100KB of resident memory with mlock C function, the code is as follows.

#include <sys/mman.h>


int main(){
char *p;
mlock(p, 100000);
sleep(100);
}

When i compiled the code with gcc i saw the following error

gcc -o mymlock mymlock.c
strace -e mlock ./mlock 
mlock(0x4c668ff4, 100000)               = -1 ENOMEM (Cannot allocate memory)

Why do i get this error if i have "fileuser - memlock unlimited" in limits.conf?

my memory usage

[fileuser@Rossetti ~]$ free -m
         total       used       free     shared    buffers     cached
Mem:          2900       2674        226          0         58        957
-/+ buffers/cache:       1657       1242
Swap:         4927        146       4781
c4f4t0r
  • 1,563
  • 15
  • 24

1 Answers1

2

My C code was wrong, now it work

New Code

#include <sys/mman.h>
#include <limits.h>


int main(){
char *p = malloc(4096*1024);
mlock(p, (4096*1024));
sleep(100);
}
c4f4t0r
  • 1,563
  • 15
  • 24