为什么在Ubuntu 18.04中定期清理/ dev / shm文件夹?

问题描述 投票:-1回答:1

我有一个与/ dev / shm文件夹配合使用的python应用。它的进程在自己的/ dev / shm / subfolder中不断创建,读取和删除二进制文件。在大多数Ubuntu服务器上,它运行正常,没有任何错误,内存泄漏。

但是有一个Ubuntu服务器的行为很奇怪。有时大约每隔一个小时(但不是严格定期)就清理整个/ dev / shm文件夹。从应用程序那里或例如手动创建的所有文件和文件夹都消失了。

该应用程序本身不执行此操作,没有引入其他应用程序,服务,守护程序来故意进行此操作。该应用程序占用的内存不能超过2000万,这远远超出了限制。

tmpfs 7.8G 8.3M 7.8G 1%/ dev / shm

是否有任何想法可能是问题的根本原因?

ipc shared-memory ubuntu-18.04
1个回答
0
投票

看这里:

superuser.com: Why are the contents of /dev/shm/ is being removed automatically

Ask Ubuntu: 16.04 LTS and /dev/shm/ Files Disappearing

经过数小时的搜索和阅读,我找到了罪魁祸首。它是为systemd设置。 /etc/systemd/logind.conf包含默认值配置选项,每个选项都被注释掉。 RemoveIPC选项默认设置为是。该选项告诉systemd清理未登录的“用户帐户”的进程间通信(IPC)in。这不会影响“系统帐户”

就我而言,文件和目录是为用户创建的帐户,而不是系统帐户。

有两种可能的解决方案:

Create the files with/for a system user -- a user created with the system option (adduser -r or adduser --system)
Edit /etc/systemd/logind.conf, uncomment the line RemoveIPC=yes, change it to RemoveIPC=no, save, and reboot the system

对于我来说,我选择了选项#2,因为用户已经已创建。

© www.soinside.com 2019 - 2024. All rights reserved.