Process restart.

Peter da Silva peter at ficc.uu.net
Sat Nov 12 03:23:32 AEST 1988


In article <16 at elgar.UUCP> ag at elgar.UUCP (Keith Gabryelski) writes:
>How does one stop a process in a way that it can be restarted after a
>cold boot?

You can't, in the general case. However it's quite feasible to make a
process snapshot itself so that it can be restarted, so long as it's
willing to re-open its files after restart. This is how the old PDP-11
Adventure program worked. I wrote a variant on this to save precompiled
FORTH executables after porting John James' PDP-11 Forth to Version 7.

Basically, you need to (1) have an 'I am restarting' flag, and...

static int restarted = 0;
void (*restart_func)();
char *restart_files[_NFILE];
char *restart_mode[_NFILE];
long restart_offset[_NFILE];

main(ac, av)
int ac;
char **av;
{
	if(restarted) {
		set restarted to 0.
		re-fopen files, and seek to the saved offsets.
		call saved restart_func.
	}

	...

}

snapshot(func)
void (*func)();
{
	if(!fork()) {
		restarted = 1;
		restart_func = func;
		abort();
	}
	if(!(fp = fopen("core", "r+"))) {
		complain();
		return FAIL;
	}
	convert core header to an a.out header, and set data end
		to _end. 
	fclose(fp);
}
-- 
Peter da Silva  `-_-'  Ferranti International Controls Corporation
"Have you hugged  U  your wolf today?"     uunet.uu.net!ficc!peter
Disclaimer: My typos are my own damn business.   peter at ficc.uu.net



More information about the Comp.unix.wizards mailing list