On Mon, Jul 05, 2021 at 10:15:19AM +0700, Victor Sudakov wrote: > FreeBSD has a simple way to run some ad-hoc program with memory limits: > > $ limits -m 2G ./mytest > memoryuse 2097152 kB > vmemoryuse infinity kB > $ limits -m 1G ./mytest > memoryuse 1048576 kB > vmemoryuse infinity kB > > How do I do the same in Linux (without root permissions)?
One way would be: (ulimit -m 2097152; ./mytest) This assumes you're using bash as your shell. You might want to review the resource limits and how they work -- see setrlimit(2) for the kernel's documentation. See "help ulimit" for bash's brief-form documentation. The longer documentation is in the bash(1) man page. You never need root privileges to *reduce* one of your resource limits to a lower value. Nor do you need root privs to raise your soft limit up to the hard limit. However, you do need root privs to raise your hard limit.