制作shell脚本守护进程的最佳方法? [英] Best way to make a shell script daemon?

查看:28
本文介绍了制作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.

推荐答案

使用系统的守护进程,例如 启动-停止-守护进程.

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

否则,是的,某处必须有一个循环.

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

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

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