我经常看到程序指定pid和lock文件。而且我不太确定他们做什么。
比如编译nginx的时候:
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
Run Code Online (Sandbox Code Playgroud)
有人可以对此有所了解吗?
我有一个 init.d 脚本来启动 crond,它为 start() 指定以下内容:
start-stop-daemon -S --quiet --make-pidfile --pidfile /var/run/crond.pid --background --exec /usr/sbin/crond
Run Code Online (Sandbox Code Playgroud)
但是,PID始终比 /var/run/crond.pid 中记录的数字高一个数字。有谁知道这里发生了什么?我有大约十个其他 init.d 脚本也进行相同的调用,只有 cron.d 有这个问题。
编辑: 这很有趣:
# /usr/sbin/crond &
#
[1]+ Done /usr/sbin/crond
# echo $!
737
# ps -eaf | grep crond
738 root /usr/sbin/crond
740 root grep crond
#
Run Code Online (Sandbox Code Playgroud) 我想更好地了解什么是后台进程。阅读这行代码后,问题就出现了:
/usr/sbin/rsyslogd -niNONE &
Run Code Online (Sandbox Code Playgroud)
文件说:
Run Code Online (Sandbox Code Playgroud)-i pid file Specify an alternative pid file instead of the default one. This option must be used if multiple instances of rsyslogd should run on a single machine. To disable writing a pid file, use the reserved name "NONE" (all upper case!), so "-iNONE". -n Avoid auto-backgrounding. This is needed especially if the rsyslogd is started and controlled by init(8).
& 符号&
似乎意味着请求该命令在后台运行,例如参见此处。
如果我的理解是正确的,pid 文件与 daemons 一起使用,即程序在后台运行时。 …