What's a good way to have a program restart itself?

Red Squirrel

No Lifer
May 24, 2003
69,736
13,351
126
www.betteroff.ca
I want to add a feature to one of my programs where if I create a specific file it will then finish, tidy up, then restart itself. This will be used when publishing a change to live so I can force it to rerun with new changes. Just to add a bit more automation into the process.

Linux allows you to overwrite an exe of a currently running program as it loads it into memory and there's no concept of "in use" so I will use this to my advantage. Replace program, create the file that tells it to restart, then it will restart and run the new exe.

I'm thinking of just using a system() call with &. Will that work ok or is there a better way?
 

Red Squirrel

No Lifer
May 24, 2003
69,736
13,351
126
www.betteroff.ca
Cool that seems to work, went with this:

Code:
	if(restart)
	{
		int err=execv(argv[0], argv);
		if(err)
		{
			cerr<<endl<<"Error "<<err<<"while restarting itself"<<endl;
		}
	}
 
Last edited: