如果进程无法自我守护,在 init 脚本中创建后台作业是一种好习惯吗?

mbr*_*nyc 5 init-script daemon

我对 *nix 相当陌生,并且遇到了删除多个进程的需要,这些进程应该在 100% 的时间运行。使用&.

我在 init.d 脚本中使用以下行来执行此操作(以用户身份运行user

su -c 'process arg1 arg2 -w - | process2 arg1 -r - &' user

(其中 -w 写入 STDOUT,-r 从 STDIN 读取)

具体来说,我知道这通常是不可接受的,因为这些过程没有很好地屏蔽外部影响。

为“服务”创建后台作业是否可以接受?

我应该使用 FIFO/命名管道来处理进程间通信吗?

如果是这样,我还应该将两个进程都创建为后台作业吗?这个稳定吗?

有关详细信息,请参阅此邮件列表线程

谢谢,

马特

Mar*_*ich 2

具体来说,我知道这通常是不可接受的,因为这些过程没有很好地免受外部影响。

为“服务”创建后台作业是否可以接受?

如果没有其他方法(即服务不会自行分叉),那么可能是的。Debianstart-stop-daemon有一个--background针对这种情况的参数:

   -b, --background
          Typically used with programs that don't  detach  on  their  own.
          This option will force start-stop-daemon to fork before starting
          the  process,  and  force  it  into  the  background.   WARNING:
          start-stop-daemon  cannot  check  the exit status if the process
          fails to execute for any reason. This is a last resort,  and  is
          only  meant  for  programs  that either make no sense forking on
          their own, or where it's not feasible to add the code  for  them
          to do this themselves.
Run Code Online (Sandbox Code Playgroud)