Create RAMDisk under MAC system and mount and uninstall via C + + shell script

Source: Internet
Author: User
1. Create RAM disk via terminal A. Creating and mounting

Open the terminal application from the Application > Utility and enter the following command:

$diskutil erasevolume hfs+ ' RamDisk ' hdiutil attach-nomount ram://xxxxx ' replaces the x character with a number representing the block size of the RAM disk's total capacity. This number is computed by multiplying the required disk size by megabytes 2048来. In our example, we will create a 4 GB RAM disk that requires 8,388,608 quantities (4096x2048). Enter this number instead of the X characters in the above command:

$diskutil erasevolume hfs+ ' RamDisk ' hdiutil attach-nomount ram://8388608 ' B. Uninstall

$ diskutil unmount/volumes/ramdisk 2. Using C + + to perform mount and uninstall commands


#include <iostream>
#include <unistd.h>
using namespace std;
int main ()
{
    system ("Diskutil erasevolume hfs+ ' ramdisk ' hdiutil attach-nomount '");
    System ("Diskutil unmount/volumes/ramdisk/");
    System ("Diskutil unmount/dev/disk7");

To build an executable program by compiling:

Mycall:mycall.cpp
g++ Mycall.cpp-o Mycall

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.