On Fri, Jan 01, 2021 at 10:02:26PM +0100, Ángel wrote:
> Yes. In fact, you can already do that using an interface exactly
> identical to file operations:
> 
> # Store a string in shared memory with key 'foo'
> echo "Hello world" > foo
> 
> # Read value of key foo
> var="$(<foo)"
> 
> 
> You only need to use that on a tmpfs filesystem, and it will be stored
> in memory. Or, if you wanted to persist your shared memory between
> reboots, or between machines, you could place them instead on a local
> or networked filesystem.

It should be noted that $(<foo) still forks a process.  If you want the
script to be faster, you'll need some other way to read the data from
the file -- perhaps using the read -r -d '' command, or the mapfile
command.

Other forms of IPC that are viable in scripts include using a FIFO that's
held open by both parent and child, or launching the child as a coprocess.

Reply via email to