查看内存大小:
[datam@hd ~]$ free
total used free shared buff/cache available
Mem: 49292728 8180244 31254348 2418992 9858136 38226156
Swap: 0 0 0
限制datam用户只能使用30G内存
[datam@hd ~]$ cat /etc/security/limits.conf
datam soft as 31457280
datam hard as 31457280
申请内存测试:
[datam@hd ~]$ cat a.c
#include<stdio.h>
#include<stdlib.h>
size_t maximum=0;
int main(int argc,char *argv[])
{
void * block;
void * tmpblock;
size_t blocksize[]={1024*1024, 1024, 1};
int i,count;
for(i=0;i<3;i++){
for(count=1;;count++){
block = malloc(maximum+blocksize[i]*count);
if(block){
tmpblock = block;
maximum += blocksize[i]*count;
free(block);
}else{
break;
}
}
}
printf("maximum malloc size = %lf GB\n",maximum*1.0 / 1024.0 / 1024.0 / 1024.0);
printf("the address is %x\n",tmpblock);
printf("the address end is %x\n", tmpblock + maximum);
//while(1);
}
[datamp@hdpprde01 ~]$ gcc -o malloc a.c
[datamp@hdpprde01 ~]$ ./malloc
maximum malloc size = 29.933483 GB
the address is e4000010
the address end is 5fbe2e6d
引用文档:https://www.cnblogs.com/mikeguan/p/7109348.html