macos OS X 是否与 /dev/shm 等效?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2033362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:40:13  来源:igfitidea点击:

Does OS X have an equivalent to /dev/shm?

linuxmacosipcramdisk

提问by Andrew Grimm

Does OS X (Snow Leopard in particular) have an equivalent to (some versions of) Linux's /dev/shm, ie something where you can write to and read from a file without necessarily touching the hard drive?

OS X(特别是Snow Leopard)是否与(某些版本的)Linux 等效/dev/shm,即您可以在不接触硬盘驱动器的情况下写入和读取文件的东西?

回答by adamse

You can create and mount a ram based disk as follows:

您可以创建和挂载基于 ram 的磁盘,如下所示:

  1. Create a disk

    $ hdiutil attach -nomount ram://$((2 * 1024 * SIZE_IN_MB))
    

    hdiutilwill return the name of the ramdisk.

  2. Format and mount the disk

    diskutil eraseVolume HFS+ RAMDisk NAME_OF_DISK
    
  3. Access the disk under /Volumes/<diskname>

    cd /Volumes/RAMDisk && touch testfile.txt && ls
    
  1. 创建磁盘

    $ hdiutil attach -nomount ram://$((2 * 1024 * SIZE_IN_MB))
    

    hdiutil将返回 ramdisk 的名称。

  2. 格式化并挂载磁盘

    diskutil eraseVolume HFS+ RAMDisk NAME_OF_DISK
    
  3. 访问下的磁盘 /Volumes/<diskname>

    cd /Volumes/RAMDisk && touch testfile.txt && ls
    

Creating a 100MB ramdisk:

创建一个 100MB 的 ramdisk:

$ hdiutil attach -nomount ram://$((2 * 1024 * 100))
/dev/disk3

$ diskutil eraseVolume HFS+ RAMDisk /dev/disk3
Started erase on disk3
Unmounting disk
Erasing
Initialized /dev/rdisk3 as a 100 MB case-insensitive HFS Plus volume
Mounting disk
Finished erase on disk3 RAMDisk

Original source: http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/

原始来源:http: //www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/