在 Unix 上正确处理 PID 文件的参考 [英] Reference for proper handling of PID file on Unix

查看:24
本文介绍了在 Unix 上正确处理 PID 文件的参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到备受推崇的参考,其中详细介绍了 Unix 上 PID 文件的正确处理?

Where can I find a well-respected reference that details the proper handling of PID files on Unix?

在 Unix 操作系统上,通常的做法是使用特殊的锁定文件:PID 文件来锁定"程序(通常是守护进程).

On Unix operating systems, it is common practice to "lock" a program (often a daemon) by use of a special lock file: the PID file.

这是一个位于可预测位置的文件,通常是/var/run/foo.pid".该程序应该在启动时检查 PID 文件是否存在,如果该文件存在,则以错误退出.所以它是一种咨询的、协作的锁定机制.

This is a file in a predictable location, often ‘/var/run/foo.pid’. The program is supposed to check when it starts up whether the PID file exists and, if the file does exist, exit with an error. So it's a kind of advisory, collaborative locking mechanism.

该文件包含一行文本,是当前持有锁的进程的数字进程 ID(因此称为PID 文件");这提供了一种简单的方法来自动向持有锁的进程发送信号.

The file contains a single line of text, being the numeric process ID (hence the name "PID file") of the process that currently holds the lock; this allows an easy way to automate sending a signal to the process that holds the lock.

我找不到关于处理 PID 文件的预期或最佳实践"行为的良好参考.有各种细微差别:如何实际锁定文件(不打扰?使用内核?平台不兼容怎么办?),处理过时的锁(静默删除它们?什么时候检查?),确切的获取和释放锁的时间,等等.

What I can't find is a good reference on expected or "best practice" behaviour for handling PID files. There are various nuances: how to actually lock the file (don't bother? use the kernel? what about platform incompatibilities?), handling stale locks (silently delete them? when to check?), when exactly to acquire and release the lock, and so forth.

我在哪里可以找到关于这个小主题的受人尊敬的、最权威的参考(最好达到 W. Richard Stevens 的水平)?

Where can I find a respected, most-authoritative reference (ideally on the level of W. Richard Stevens) for this small topic?

推荐答案

据我所知,PID 文件是一种约定,而不是您可以找到受人尊敬的、主要是权威来源的文件.我能找到的最接近的是文件系统层次结构标准的本节.

As far as I know, PID files are a convention rather than something that you can find a respected, mostly authoritative source for. The closest I could find is this section of the Filesystem Hierarchy Standard.

这个 Perl 库 可能会有所帮助,因为它看起来像作者至少考虑了一些可能出现的问题.

This Perl library might be helpful, since it looks like the author has at least given thought to some issues than can arise.

我相信/var/run 下的文件通常由发行版维护者而不是守护程序的作者处理,因为发行版维护者有责任确保所有 init 脚本一起运行良好.我查看了 Debian 和 Fedora 的开发人员文档,但找不到任何详细的指南,但您可以在他们的开发人员邮件列表中获得更多信息.

I believe that files under /var/run are often handled by the distro maintainers rather than daemons' authors, since it's the distro maintainers' responsibility to make sure that all of the init scripts play nice together. I checked Debian's and Fedora's developer documentation and couldn't find any detailed guidelines, but you might be able to get more info on their developers' mailing lists.

这篇关于在 Unix 上正确处理 PID 文件的参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆