Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following script which I run using the command:

./ 2>&1 &

and if I kill the sub process spawned by it, after a few seconds it is restarted. Why is this?


#other stuff

while true; do
         nohup /usr/bin/php ../thing/script.php scriptargs >my_log.log 2>&1
        /bin/mail -s "$SUBJECT" "" < $EMAILMESSAGE

the result of

     ps -ax | grep scriptargs


19624 pts/0    S      0:00 /bin/bash ./
19643 pts/0    S      0:00 /usr/bin/php ../thing/script.php scriptargs
19771 pts/0    S+     0:00 grep scriptargs

if I run

kill 19643

I get:

./ line 24: 19643 Terminated /usr/bin/php ../thing/script.php scriptargs >my_log.log 2>&1

but if then run:

     ps -ax | grep scriptargs

again I get:

19624 pts/0    S      0:00 /bin/bash ./
19824 pts/0    S      0:00 /usr/bin/php ../thing/script.php scriptargs
19862 pts/0    S+     0:00 grep scriptargs

I get the email - but then it respawns that process.

Why is this?

share|improve this question
up vote 3 down vote accepted

This would be because of the loop

while true; do


When the process gets killed, it exits and allows the mail to be sent. The shell then hits the done statement and loops back the the while true which is erm true so it runs the commands within, again.

share|improve this answer
In other words: You kill just the sub-process so the main script keeps looping around the while and starts the script again. You will have to kill both the main process and the sub-process. – Tonny Oct 5 '12 at 14:04
so I don't actually need a loop. The parent script will await the execution of the sub script. – Stevo Oct 5 '12 at 14:30
@Stevo: Yes, if that's what you want. – Iain Oct 5 '12 at 14:32
Cool - that's aided my understanding. I should have started my comment with a D'Oh! – Stevo Oct 5 '12 at 14:37

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.