小编Ham*_*148的帖子

写入映射数据时出现总线错误

当我上学期第一次做这个项目时,代码运行得很好。现在,当写入要在进程之间共享的映射内存时,我收到总线错误,并且我不确定为什么它不再工作。

Account_Info *mapData()
{
    int fd;
    //open/create file with read and write permission and check return value
    if ((fd = open("accounts", O_RDWR|O_CREAT, 0644)) == -1)
    {
            perror("Unable to open account list file.");
            exit(0);
    }

    //map data to be shared with different processes
    Account_Info *accounts = mmap((void*)0, (size_t) 100*(sizeof(Account_Info)), PROT_WRITE,
    MAP_SHARED, fd, 0);

    int count= 0;

    //loop to initialize values of Account_Info struct
    while (count != 20)
    {
            //bus error occurs here
            accounts[count].CurrBalance= 0;
            accounts[count].flag = 0;
            int i = 0; …
Run Code Online (Sandbox Code Playgroud)

c mmap shared-memory bus-error

4
推荐指数
1
解决办法
2851
查看次数

标签 统计

bus-error ×1

c ×1

mmap ×1

shared-memory ×1