linux - 执行一个正在运行的进程

标签 linux bash

我目前有一个 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/

相关文章:

linux - 断开连接时启动网络连接的脚本

c - Linux/C : Writing command-line arguments to a text file as separate lines?

linux - 如何在 Vim 中的行首和行尾添加/*?

Python循环下载多个文件

BASH:在同一行中打印两行文件

bash - 检查给定字符是否为空格

linux - 如何在所有shell脚本中添加 "shopt -s compat31"命令?

linux - Rhel 中的每个命令都会返回错误

linux - 运行 hcitool 到变量使用 IFS

linux - Sed 错误 : bad option in substitution expression