巴什 - 我应该怎么闲着,直到我得到的信号? [英] Bash – How should I idle until I get a signal?

查看:143
本文介绍了巴什 - 我应该怎么闲着,直到我得到的信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对的launchd运行启动服务器的脚本,然后告诉它的时候的launchd杀死其关闭(这应该是在关机时)正常退出。我的问题:什么是合适的,惯用的方式来告诉脚本空闲直到它得到的信号?如果我只是用一个,而真睡眠-1环,还是有更好的方法来做到这一点?

 #!/斌/庆典CD目录名`$ 0`陷阱./serverctl停止一词
./serverctl启动#等待接收TERM信号。


解决方案

一个普通的是资源密集型的显著不到一个自旋锁,即使在睡眠吧。

I have a script for launchd to run that starts a server, then tells it to exit gracefully when launchd kills it off (which should be at shutdown). My question: what is the appropriate, idiomatic way to tell the script to idle until it gets the signal? Should I just use a while-true-sleep-1 loop, or is there a better way to do this?

#!/bin/bash

cd "`dirname "$0"`"

trap "./serverctl stop" TERM
./serverctl start

# wait to receive TERM signal.

解决方案

A plain wait would be significantly less resource-intensive than a spin lock, even with a sleep in it.

这篇关于巴什 - 我应该怎么闲着,直到我得到的信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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