做一个shell脚本守护进程的最佳方式? [英] Best way to make a shell script daemon?

查看:591
本文介绍了做一个shell脚本守护进程的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有更好的方法,使只使用比SH的东西等待一个后台程序:

I'm wondering if there is a better way to make a daemon that waits for something using only sh than:

#! /bin/sh
trap processUserSig SIGUSR1
processUserSig() {
  echo "doing stuff"
}

while true; do
  sleep 1000
done

在我特别想知道是否有任何的方式来摆脱循环,仍然有东西监听信号。

In particular, I'm wondering if there's any way to get rid of the loop and still have the thing listen for the signals.

推荐答案

使用系统的后台程序设施,如<一个href=\"http://manpages.ubuntu.com/manpages/karmic/man8/start-stop-daemon.8.html\">start-stop-daemon.

Use your system's daemon facility, such as start-stop-daemon.

否则,是的,必须有一个循环的地方。

Otherwise, yes, there has to be a loop somewhere.

这篇关于做一个shell脚本守护进程的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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