相关疑难解决方法(0)

当我的shell脚本退出时,如何终止后台进程/作业?

当我的顶级脚本退出时,我正在寻找一种清理混乱的方法.

特别是如果我想使用set -e,我希望后台进程会在脚本退出时死掉.

shell

173
推荐指数
7
解决办法
9万
查看次数

在Bash中识别接收到的信号名称

收到信号后,我可以使用执行某些命令trap.例:

trap 'echo hello world' 1 2
Run Code Online (Sandbox Code Playgroud)

如果收到任何指定的信号,则显示"hello world".

但是如何打印/识别收到的信号名称?

linux bash shell

33
推荐指数
5
解决办法
1万
查看次数

Bash 陷阱、捕获并将它们作为同一函数的参数传递

我正在开发一个管理一些陷阱的脚本。一开始我只用这段代码管理 INT 和 SIGTSTP,它运行得很好:

#!/bin/bash
function capture_traps() {
    echo -e "\nDoing something on exit"
    exit 1
}

trap capture_traps INT
trap capture_traps SIGTSTP
read -p "Script do its stuff here and we use read for the example we pause for time to generate trap event"
exit 0
Run Code Online (Sandbox Code Playgroud)

然后我尝试添加我想要管理的新陷阱,即 SIGINT 和 SIGHUP。首先,我这样做了(这是有效的):

#!/bin/bash
function capture_traps() {
    echo -e "\nDoing something on exit"
    exit 1
}

trap capture_traps INT
trap capture_traps SIGTSTP
trap capture_traps SIGINT
trap capture_traps SIGHUP
read -p "Script do …
Run Code Online (Sandbox Code Playgroud)

bash bash-trap

4
推荐指数
1
解决办法
1299
查看次数

标签 统计

bash ×2

shell ×2

bash-trap ×1

linux ×1