我目前有一个 Bash 脚本,它在末尾使用 exec
来启动正在运行的服务器进程:
#! /bin/bash
.
.
.
exec python -m SimpleHTTPServer 8080
但是现在,我不想只是 exec
命令,而是想在 exec
压缩我的调用 shell 程序之前“预热”服务器进程。有点像:
#! /bin/bash
python -m SimpleHTTPServer 8080 &
for index in $(seq 100); do
curl -X GET http://localhost:8080/warm/up
done
# => How can I exec when my command is already running?
据我了解,exec
只能接受命令,而不能接受正在运行的进程PID或其他东西。
在这种情况下,我真的不想将调用 Bash shell 作为我的 python
服务器的父级,以避免父级中出现任何信号处理陷阱。
最佳答案
只需背景热身而不是服务器:
#! /bin/bash
{
sleep 5
for index in $(seq 100); do
curl -X GET http://localhost:8080/warm/up
done
} &
exec python -m SimpleHTTPServer 8080
关于linux - 执行一个正在运行的进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50686323/