[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Shared memory in bash
From: |
Peng Yu |
Subject: |
Re: Shared memory in bash |
Date: |
Wed, 14 Apr 2021 09:28:21 -0500 |
It is more straightforward to use variables in many cases. Would it
make sense to add a feature in bash so that an attribute can be
assigned to variables to indicate the variables can be share with the
parent process?
On 4/13/21, Koichi Murase <myoga.murase@gmail.com> wrote:
> 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
>
--
Regards,
Peng