Path: utzoo!attcan!uunet!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.unix.wizards Subject: Re: Process restart. Keywords: Fork, Process, migration, remote, a.out, core Message-ID: <2199@ficc.uu.net> Date: 11 Nov 88 17:23:32 GMT References: <16@elgar.UUCP> <8831@smoke.BRL.MIL> <17@elgar.UUCP> Organization: SCADA Lines: 52 In article <16@elgar.UUCP> ag@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@ficc.uu.net