Stephen Chu
Stephen Chu

Reputation: 373

Exec a running process

I currently have a Bash script that uses exec at the end to spin up a running server process:

#! /bin/bash
.
.
.
exec python -m SimpleHTTPServer 8080

But now, instead of just exec-ing the command, I'd like to "warm up" the server process before exec squashes my calling shell program. Kind of like:

#! /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?

As I understand it, exec can only take a command, but not a running process PID or something.

I really don't want to leave a calling Bash shell as the parent of my python server in this case, to avoid any signal-handling pitfalls in the parent.

Upvotes: 2

Views: 824

Answers (2)

that other guy
that other guy

Reputation: 123750

Just background your warmup instead of your server:

#! /bin/bash

{
  sleep 5
  for index in $(seq 100); do
    curl -X GET http://localhost:8080/warm/up
  done
} &

exec python -m SimpleHTTPServer 8080

Upvotes: 3

glenn jackman
glenn jackman

Reputation: 247250

Do this to launch the server and disassociate it from the shell process

nohup python -m SimpleHTTPServer 8080 &
disown

Then you can call your warmup urls and simple let the script exit.

Upvotes: 0

Related Questions