【问题标题】:Sending signal to process in background向后台进程发送信号
【发布时间】:2014-01-22 10:53:07
【问题描述】:

我正在编写简单的 http 应用程序并对其进行测试,我需要通过 curl 等进行一些请求。但这让我在 tmux 中切换窗格,我很懒惰。这样的事情可能吗:

我有一些 script.sh(伪代码):

while(true) { wait for SOME_SIG curl url }

我在终端运行:

./script.sh &

./服务器

所以我当前的进程是server。我是否有可能向后台进程发送信号 - script.sh 发出 curl 请求?

【问题讨论】:

    标签: linux bash unix terminal


    【解决方案1】:

    您可以使用trap。例如,以下脚本将在收到SIGABRT 时执行函数foo

    foo() {
      echo "I received SIGABRT; lets do something here"
    }
    
    trap foo SIGABRT
    
    while : ; do
      sleep 5s
    done
    

    (详细地说,kill -ABRT pid 其中pid 指的是上述脚本的数字PID 将触发foo。)

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 2016-03-21
      • 2017-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 2012-06-26
      • 2017-07-11
      相关资源
      最近更新 更多