linux系统限制

一次偶然的共享内存打开失败

int shm_fd;
shm_fd = shm_open(shm_name,  O_CREAT | O_RDWR | O_LARGEFILE, S_IWUSR | S_IRUSR);
if(shm_fd == -1)
{
    fprintf(stderr, "open shm failed errno[%d] [%s]\n", errno, strerror(errno));
    return -1;
}
int ret = ftruncate(shm_fd, shm_size);
if(ret != 0)
{
    fprintf(stderr, "ftruncate64 failed size[%lu] [%d] [%s]\n", shm_size, errno, strerror(errno));
    return -1;
}

shm_size设置为** 4 * 1024 * 1024 * 1024(4GB) **
在ftruncate一直返回errorno 22,无效参数。

EINVAL The argument length is negative or larger than the maximum
file size

我以为是ftruncate不支持太大的内存设置,专门搜相关资料

open

O_LARGEFILE
open设置这个属性,但是发现没有作用

ulimit

ulimit -a 查看进程限制

[root@localhost bin]# ulimit -a 
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 126767
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 126767
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

修改配置在 /etc/security/limits.conf
应该也不是这里的问题

iniparser

最后定位到是iniparser_getint 返回的值有问题
采用

char str_shm_size[128];
strncpy(str_shm_size, iniparser_getstring(ini, section_name, "8589934592"), sizeof(str_shm_size));
s_config.m_stored_shm_size = strtol(str_shm_size, NULL, 0);
printf("m_stored_shm_size %ld\n", s_config.m_stored_shm_size);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值