有一个名为mimosa (https://github.com/dbashford/mimosa)的nodejs脚本
Nodejs使用USR1将正在运行的进程切换到调试模式
下面是我手动操作的方法
$ cd myproj
$ mimosa watch -s # this runs node /path/to/mimosa watch -s
22:16:03 - Watching /Users/admin/Work/test-mimosa/assets
... # some more output
# check the pid from a different terminal
$ ps aux | grep mimosa
admin 79284 0.7 0.8 3153812 129272 s006 S+ 10:16PM 0:03.57 node /opt/local/bin/mimosa watch -s
# send debug signal from the 2nd terminal
kill -s USR1 79284
# nodejs output in the 1st terminal
Hit SIGUSR1 - starting debugger agent.
debugger listening on port 5858如果我将mimosa作为后台进程(mimosa watch -s &)运行,也是如此
现在我需要自动化这个过程:运行mimosa,获取其pid,发送USR1,等待用户的SIGTERM,杀死mimosa:
mimosa watch -s &
pid=$!
echo "mimosa pid: $pid"
trap "echo '\nSTOP'; kill $pid; exit" SIGHUP SIGINT SIGTERM
echo 'send debug'
kill -s USR1 $pid
wait $pid此脚本立即退出,mimosa进程也立即退出(我再次使用grep进行检查)。控制台中的输出
$ ./debug.sh
mimosa pid: 79516
send debug
./debug.sh: line 11: 79516 User defined signal 1: 30 mimosa watch -s出什么问题了,怎么解决?
发布于 2014-02-20 21:15:05
当您发送调试信号时,mimosa是否会向自己的进程组发送信号?这就可以解释了。
在交互式shell中,执行./program会使用自己的进程组启动程序。如果程序执行类似kill -s USR1 0的操作,它将永远不会退出该组。
在非交互式shells /脚本中,执行./program将作为子进程启动,但在同一进程组中。如果该子进程执行kill -s USR1 0,它将终止调用脚本。
您可以在debug.sh中执行trap 'echo ignoring' USR1 USR2,以防这些信号是由mimosa发送的。
或者,在启动mimosa之前,尝试使用set -m打开作业控制。
另请参阅I have "trap 'echo ignore' USR1" in my called script, why does the calling script get killed?
https://stackoverflow.com/questions/16266808
复制相似问题