Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 2, 2008, 11:15 AM   #1
dzwiedziu
macrumors newbie
 
Join Date: Oct 2008
Ulimit doesn't work (memory)

I've wrote sample program in C++:

#include<cstdio>
#include<cstdlib>
long long T[5000000];
int main(){
for(int i=0;i<5000000;i++) T[i]=rand()%5000000;
for(int i=0;i<5000000;i++) T[i]=T[rand()%5000000];
printf("%lld\n",T[rand()%5000000]);
return 0;
}

It uses memory: ~40MB

But when I check it in terminal:


dzwiedziu:~/test_ulimit # ulimit -v 1000
dzwiedziu:~/test_ulimit # ./test
1480040
dzwiedziu:~/test_ulimit # ulimit -H -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) 1000
open files (-n) unlimited
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 65532
cpu time (seconds, -t) unlimited
max user processes (-u) 532
virtual memory (kbytes, -v) 1000


This program should be killed. I've worked on linux for 4 years. What's wrong?
dzwiedziu is offline   0 Reply With Quote
Old Oct 2, 2008, 11:30 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Where are you getting the 40Mb figure from? If it's VSize in Activity Monitor then you're looking at it wrong...
robbieduncan is offline   0 Reply With Quote
Old Oct 2, 2008, 11:36 AM   #3
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by dzwiedziu View Post
I've wrote sample program in C++:

#include<cstdio>
#include<cstdlib>
long long T[5000000];
int main(){
for(int i=0;i<5000000;i++) T[i]=rand()%5000000;
for(int i=0;i<5000000;i++) T[i]=T[rand()%5000000];
printf("%lld\n",T[rand()%5000000]);
return 0;
}

It uses memory: ~40MB

But when I check it in terminal:


dzwiedziu:~/test_ulimit # ulimit -v 1000
dzwiedziu:~/test_ulimit # ./test
1480040
dzwiedziu:~/test_ulimit # ulimit -H -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) 1000
open files (-n) unlimited
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 65532
cpu time (seconds, -t) unlimited
max user processes (-u) 532
virtual memory (kbytes, -v) 1000


This program should be killed. I've worked on linux for 4 years. What's wrong?
Man Page: "ulimit: Control the resources available to a process started by the shell, on systems that allow such control."

Seems to do exactly what the man page says, and seems that MacOS X is not a system that allows such control, or maybe it has a default that you can't go below (like 64 MB) or whatever. Feel free to file a bug report with Apple. They'll probably tell you "works as designed".
gnasher729 is offline   0 Reply With Quote
Old Oct 2, 2008, 11:37 AM   #4
dzwiedziu
Thread Starter
macrumors newbie
 
Join Date: Oct 2008
Quote:
Originally Posted by robbieduncan View Post
Where are you getting the 40Mb figure from? If it's VSize in Activity Monitor then you're looking at it wrong...
I looked in Activity Moniton on Real Memory. But it's easy to count long long need 8 bytes so this array need 5000000 * 8 bytes.

When I set limit on 1kb I've the same effect:
dzwiedziu:~/test_ulimit # ulimit -v 1
dzwiedziu:~/test_ulimit # ./test
1480040
dzwiedziu:~/test_ulimit # ulimit -H -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) 1
open files (-n) unlimited
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 65532
cpu time (seconds, -t) unlimited
max user processes (-u) 532
virtual memory (kbytes, -v) 1
dzwiedziu is offline   0 Reply With Quote
Old Oct 2, 2008, 11:42 AM   #5
foidulus
macrumors 6502a
 
Join Date: Jan 2007
Quote:
Originally Posted by gnasher729 View Post
Man Page: "ulimit: Control the resources available to a process started by the shell, on systems that allow such control."

Seems to do exactly what the man page says, and seems that MacOS X is not a system that allows such control, or maybe it has a default that you can't go below (like 64 MB) or whatever. Feel free to file a bug report with Apple. They'll probably tell you "works as designed".
It worked in Tiger, however it has been removed from Leopard, probably because it was hard to integrate with some of the memory randomization schemes Apple implemented with Leopard.
foidulus is offline   0 Reply With Quote
Old Oct 2, 2008, 11:49 AM   #6
dzwiedziu
Thread Starter
macrumors newbie
 
Join Date: Oct 2008
Quote:
Originally Posted by foidulus View Post
It worked in Tiger, however it has been removed from Leopard, probably because it was hard to integrate with some of the memory randomization schemes Apple implemented with Leopard.

Thx. Maybe you know, is any similary program to ulimit on Leopard, or any way to kill procces when it use to much memory.
dzwiedziu is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Upgrade RAM: Two, 2GB memory cards or will one 4GB memory card work? cmhall9 MacBook Pro 10 Nov 4, 2014 07:54 AM
Black screen , HDMI doesn't work , VGA doesn't work Madridista Mac Basics and Help 4 Jun 23, 2014 06:45 PM
Deleting Files Doesn't Free Up Memory wantonbudgie Mac OS X 10.7 Lion 5 Oct 27, 2013 11:29 AM
VPN by iPhone work but at MacBook doesn't work! why ? Jingol Mac Basics and Help 1 Sep 12, 2013 05:40 PM
Camera memory doesn't mount when plugged into USB Diogones Mac OS X 10.7 Lion 0 Sep 27, 2012 08:15 PM

Forum Jump

All times are GMT -5. The time now is 04:57 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC