help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shared memory in bash


From: Koichi Murase
Subject: Re: Shared memory in bash
Date: Tue, 13 Apr 2021 18:39:06 +0900

2021年4月12日(月) 22:46 Peng Yu <pengyu.ut@gmail.com>:
> In bash, I only know a subshell can access data in the parent shell,
> but not the reverse. One could use files to share data from the
> subshell to the parent shell. But is there a more efficient way to do
> so, such as by mmap?

I think it's not as efficient as mmap, but you could use in-memory
filesystems (tmpfs) to share data among different processes.  For
example, in Linux, tmpfs mounts on /dev/shm (shm stands for shared
memory) where you can create a temporary file/directory using mktemp.
You can also use /run/user/$UID in systemd-based systems.  Other
systems may provide /tmp as an in-memory filesystem.

A file on in-memory filesystems may be used as if it is a normal file,
so in order to share the data, one needs to read/write the data
from/to the file through file descriptors.  Also, one needs to care
about synchronization using flock, semaphore, mutex, or some other
way.

Koichi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]