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

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

问题描述

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

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

这是一个可预测位置的文件,通常为"/var/run/foo.pid".该程序应该在启动时检查PID文件是否存在,如果该文件确实存在,则退出并返回错误.因此,这是一种咨询,协作锁定机制.

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

对于处理PID文件的预期或最佳实践"行为,我找不到很好的参考.有各种细微差别:如何实际锁定文件(不要打扰?使用内核?平台不兼容该怎么办?),处理陈旧的锁(静默删除它们?何时检查?),何时确切地获取和释放锁? ,依此类推.

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

解决方案

据我所知,PID文件是一种约定,而不是您可以找到值得关注的,主要是权威性来源的文件.我能找到的最接近的是文件系统层次结构标准的本节. /p>

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

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

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

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.

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.

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.

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.

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

解决方案

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.

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

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天全站免登陆