douwei3280 2013-05-17 12:14 采纳率: 0%
浏览 52
已采纳

此mmap系统调用有什么问题?

This is an attempt to mmap a file and write a single byte:

package main

import (
  "fmt"
    "os"
    "syscall"
)

func main() {
    file, _ := os.Open("/tmp/data")
    mmap, _ := syscall.Mmap(int(file.Fd()), 0, 100, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
    fmt.Printf("cap is %d", cap(mmap))
    mmap[0] = 0
    syscall.Munmap(mmap)
}

Despite length is set to 100, mmap capacity is always 0. What went wrong in the system call?

  • 写回答

2条回答 默认 最新

  • dpcj32769 2013-05-17 12:21
    关注

    Always check for error!

    os.Open opens a file for reading only, however mmap call asks to map the file read/write, thus giving a permission denied error, and as a result mapped region size is 0.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥33 集成BiLSTM模型和GCN模型时,前模型的输出不匹配后模型的输入
  • ¥15 关于液体厚度提取,和铺展轨迹数据化处理
  • ¥20 对方微信是wxid如何添加成好友?或者转换成微信号?
  • ¥15 yolov5实验数据好,但是自己拍摄的照片检测结果差
  • ¥15 做过dali2.0认证的技术,
  • ¥15 一道python难题
  • ¥15 matlab 免疫算法
  • ¥50 可视化界面构建,实现信息模块功能
  • ¥15 基于bert-base-chinese的中文文本处理
  • ¥15 高价求抖音抓包技术,抖音抓包无网络问题