简体   繁体   中英

create a ramdisk in C++ on linux

I need to make a ramfs an mount it to an directory in linux using c++ . I want to make it like a user (no sudo ).

I need to call an application on a file that i created and it will be often. Writing it to HDD is very slow.

I found just:

system("mkdir /mnt/ram");
system("mount -t ramfs -o size=20m ramfs /mnt/ram");

but that is not good. I want to be a regular user, and command mount can be called just as root. what can i do?

I checket if /tmp is a ramfs, but it is not. It creates files on the HDD. but when i run df -h it outputs:

rootfs                       25G  9,4G   15G  40% /
devtmpfs                    1,9G     0  1,9G   0% /dev
tmpfs                       1,9G  1,6G  347M  83% /dev/shm
tmpfs                       1,9G  1,3M  1,9G   1% /run
/dev/mapper/vg_micro-root    25G  9,4G   15G  40% /
tmpfs                       1,9G     0  1,9G   0% /sys/fs/cgroup
tmpfs                       1,9G     0  1,9G   0% /media
/dev/mapper/vg_micro-stack  289G  191M  274G   1% /stack
/dev/mapper/vg_micro-home   322G   40G  266G  14% /home
/dev/sda2                   485M   89M  371M  20% /boot
/dev/sda1                   200M   19M  182M  10% /boot/efi

This means that tmpfs (ramdisks) are: /dev/shm , /run , /sys/fs/cgroup and /media . But only one of this is meant to be a temporary ramdisk for comunication between processes, using files. Here is the /dev/shm description and usage. The only thing is that tmpfs will not grow dynamically , but for my purposes it will be enough (20MB - 1GB).

对于userspace ramfs解决方案,您可以使用python-fuse-ramfs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM