Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So far I used

trap " call function" 2 


but it never reaches the exit line and a whole bunch of process piles up any one got any idea?

I tried & (bg) but i need to be able to keep doing it , the bg only allows me to do it once The point of it is when i type ctrl C it should terminate the original but it should also call itself before terminating hence create a new process.

This is what i have so far

while [ 1 ]

echo $count
count=`expr $count + 1`


trap "restart" 2 ( for the ctrl c)


 exit ( it never reaches here therefore it doesnt kill the original process which is what i need otherwise it works fine)

share|improve this question
Create a copy of what? It's not clear what you're trying to do exactly. –  David Schwartz Nov 14 '11 at 9:40
you won't reach exit, since you are recusing on the same script on and on....before calling ./ you should probably invoke cp utility and make a copy of the file(since that's ur aim. But even then, you won't reach exit!! You should have a terminating criterion, probably an statement. –  Vineet Menon Nov 14 '11 at 9:43
a nice collection of self replicating scripts... –  Vineet Menon Nov 14 '11 at 9:45
@DavidSchwartz its suppose to create a copy of itself ( the process) and terminate the original one , the problem is that I cant get to to kill itself and start a new one at the same time its either start an new one or terminate it –  ricedragon Nov 15 '11 at 2:19
The shell doesn't provide a mechanism to create a copy of the process. Rather than trying to copy the existing process, why not just create a new process? –  David Schwartz Nov 15 '11 at 2:45

Your Answer


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

Browse other questions tagged or ask your own question.