Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement shared memory in shell scripting?

I have a shell script which gets triggerred and runs at regular interval again and again on linux system, say every 45 mins. I need to share certain information between different runs of this shell script. What are different ways I can implement this? This is somewhat similar to interprocess communication. I dont want to use disk I/O so no file creation. Something I can create in memory and can keep it alive for some time duration e.g. 7AM to 12AM etc. During this time, the scripts runs say 20 times and uses/populates that data structure again and again. The values populated in previous run need to be used in next run by the script.

Basically I am looking for something which works like DB but faster and modifying that is less expensive operation. So I will keep my data in that DB like thing and all differnt runs of script will read/modify that thing instead of going to DB again and again. /dev/shm looks good option unless someone suggests better option.


1 Answers

I dont want to use disk I/O so no file creation.

If you're on a Linux system, create a file in /dev/shm. Files stored in this directory are only stored in shared memory; they are not written to disk.

Depending on your system configuration, /tmp and/or /var/tmp may be mounted as a tmpfs, making them behave the same way. Your mileage may vary.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!