存储以用户身份运行的守护进程的 pid 文件

发布于 2024-09-27 21:01:51 字数 137 浏览 0 评论 0原文

是否有一个首选位置来存储作为用户运行的守护进程的 pid 文件? /var/run 是标准位置,但这是针对用户守护程序的,因此它在那里没有写权限。大概我的守护进程将从 .profile 或 .bashrc 或其他东西启动。将其保存到 /tmp 是一个坏主意吗?

Is there a preferred place to store a pid file for a daemon that's run as a user? /var/run is the standard place, but this is for a user daemon so it doesn't have write privileges there. Presumably my daemon will be started from .profile or .bashrc or something. Is just saving it to /tmp a bad idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紅太極 2024-10-04 21:01:51

如果它是为用户运行的,让我们看看存在哪种类型的特定于用户的存储。

嗯。

就是这样!主目录。我知道它最终会降临到我身上:-)


抱歉,我的攻击很轻。说真的,我只是将 PID 存储到 $HOME/.daemon.pid~/.daemon.pid (当然,如何命名文件取决于您) 。

当然,这是假设您只为一个用户运行一个守护程序。如果没有,你就需要采取一些技巧。


希望减轻您对用户会无意中删除其主目录中未知文件的担忧,这就是为什么您通过以 . 字符开头来将其“隐藏”。

大多数没有经验的用户根本不应该看到这些内容,而有经验的用户应该知道不要乱搞它们。

If it's being run for a user, let's see, what sort of storage exists that is user-specific.

Hmmm.

That's it! The home directory. I knew it would come to me eventually :-)


Sorry for the light jab. Seriously, I would just stash the PID into $HOME/.daemon.pid or ~/.daemon.pid (how you name the file is up to you of course).

This is, of course, assuming you will only have one daemon running for a user. If not, you'll need to be a bit trickier.


And hopefully allaying your fears that a user will inadvertently delete unknown files in their home directory, that's why you make it "hidden" by starting it with a . character.

Most non-experienced users should never even see these and experienced users should know better than to muck about with them.

郁金香雨 2024-10-04 21:01:51

XDG Basedir 规范 定义了您应该存储这些内容的位置。
变量 $XDG_RUNTIME_DIR 定义其位置,但没有默认值。
最常见的后备(如果未设置该变量)是 /tmp/service-$USER.id

这有助于保持主目录整洁,同时将所有运行时数据保存在

The XDG Basedir specification defines where you should store these.
The variable $XDG_RUNTIME_DIR defines it's location, although it has no default.
The most common fallback (if the variable is unset) is /tmp/service-$USER.id.

This helps keep uncluttered homedirs, while keeping all runtime data in

等往事风中吹 2024-10-04 21:01:51

我建议您转到用户主目录中的子目录。

~/.programname/.pid

如果还有任何其他用户配置数据,您也可以将其存储在这里,以避免主目录混乱。

I suggest you go for a subdirectory within the user's home directory.

~/.programname/.pid

If there is any other user configuration data, you can store that in here too, in order to avoid cluttering up the home directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文