How can I reduce the memory allocated for a given program from the terminal?
what I mean is if I have a a.out
executable file, how can I make it run in a less memory from the terminal ( with out using any special applications)
$./a.out fooo
so that my program a.out runs on very less space.
As far as I know, you can't in a strict way (unless using some kind of virtual machine or using cgroups which is not so easy; you can see this answer from @muru.).
You can limit the memory available with
ulimit
, but this will simply have the effect of telling your program that there is no more memory when doing an allocation, or crashing it with a signal if it doesn't handle the out-of-memory condition. Look:it works, lot of output
(This is limiting the memory for data and for core to 100 kB)
But the shell is still able to see all the memory:
Edit: more info in this unix.se post.
You can do this with the
ulimit
command, here's it's manpage .