Restarting a process after a shutdown

Vadim G. Antonov avg at hq.demos.su
Mon Sep 3 20:55:23 AEST 1990


In article <5759 at ethz.UUCP> tilo at tilo@nmr.lpc.ethz.ch (Tilo Levante) writes:
>Is there a way to save the status of a process and restart it
>after the shutdown?

	Of course, Unix allows you to do such things.
	You can do it as follows:

	Write a signal handler for SIGKILL:

	- scan through file descriptors (with fstat)
	  and detect opened ones and their types (TTY, disk file,
	  directory) and offsets from the beginning;
	- open a save-file
	- store open files status information into the file
	  You have to keep names of opened files (use your own
	  version of _open and _create syscalls).
	- save the stack (from the top of stack, depends
	  on your system/machine) to this file
	  by write syscall
	- save the data segment (from _etext ptr to _end ptr
	  or from address 0 to _end - if you use a separate mode).
	  Some systems require more detailed investigation
	  of segments layout.
	- make setjmp C-library routine with the given jmp_buf
	  IF it returns 0 THEN
		save jmp_buf into the file
		_exit(0)
	  FI
	- read file descriptors information from the save-file
	  and perform appropriate setup (open files, seek, etc)
	- perform a program re-initialization actions (it may
	  be redrawing screen, etc)
	- return

	Write a special branch into _main:

	- if there is no save file, run as usually
	- otherwise call an assembly routine, which goes the following
	  way:

	- expands the stack by touching the stack's lower memory
	  cell (or calls a stack-expanding routine on some systems)
	- reads the stack segment in  (using read system call,
	  NOT read C-library routine)
	- reads the data segment
	- restores the stack ptr & instruction pointer from the
	  saved jmp_buf

	Of course, this way is extremely tricky and requires an
	assembly programming and the brilliant knowledges on
	internals of the ur system; but it's possible.
	I've done such a thing seven years ago on Unix v6.

	Lucky Hacking!

	Vadim Antonov,
	DEMOS, Moscow, USSR
	(It is NOT a joke!)



More information about the Comp.unix.questions mailing list