Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have a python script which I would like to run in the background. So I do this:

$ nohup python &

If I am frequently making changes to the script, I need to terminate the process and run the script again.

$ kill -9 <pid_of_bg_process>
$ nohup python &

Is is possible to reload the process without terminating it?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Short answer - no.

Long answer: You are actually calling a python interpreter. That interpreter loads the and parses it.

If you change the script it has to reload the file and start from the beginning, since the interpreter has no way to know which part was changed.

Now if your goal is to simply signal python to reload/restart the script, you can wrap it into a shell-script:

  pkill -f "$LINE"
  exit 0
trap stop 1
trap clean 9 15
while true
    $LINE &

You can now start that shell-script (in background, with nohup, if you like). If you send a HUP signal to it, it will restart your python process.

If you kill the wrapper process the python script will terminate, too.

I did not test my script - but the idea should be clear.

share|improve this answer
I had also planned to create a wrapper script too, since I had a feeling that what I asked might not be possible. But my thought was vague and your script puts me in a good direction. Thank you so much. – Nanda Apr 27 '12 at 0:43

you can use kill -USR1 PID or pidof also -9 is brutal to terminate the process , try -15 for graceful exit .

share|improve this answer
I thought 9 was for SIGTERM and I was wrong. Thank you for pointing it out. 15 was what I intended to use as well. – Nanda Apr 27 '12 at 0:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.