Check out the new USENIX Web site. next up previous
Next: System calls Up: Design and implementation Previous: Virtual machine initialization and

Process creation and destruction

When a new process is created, the generic kernel creates the task structure for the new process and calls the arch layer to do the machine-dependent part. This port creates a new process in the host for each new process in the virtual machine. This is done by the tracing thread. It needs to ptrace all new processes, and that is simplified if it's their parent.

The new thread starts life in a trampoline which does some initialization. It sets up its signal handlers for SIGSEGV, SIGIO, and SIGVTALRM, initializes the timer, and sets itself to be ptraced by its parent.

Once this initialization is done, it sends itself a SIGSTOP. When the tracing thread sees the thread stop itself, it sets the thread's system call return value to zero, while the same system call in the forking process returns the pid of the new process.

At this point, the parent's fork or clone is finished, and it returns.

At some later point, the new process will be scheduled to run. It is necessary that a process call schedule_tail before it's rescheduled. Also, the kernel stack state needed to start a system needs to be saved. Both of these are done at this point. Another signal is delivered to the new process, and the handler calls schedule_tail, goes into the system call handler, and stops itself. The tracing thread captures the process state at this point. Then the registers of the forking process (except for the one reserved for the system call return value, which is now zero) are restored, and the process is continued. Since the generic kernel arranged for the new address space to be a copy of the parent address space, and the new process has the same registers as the old one, except for the zero return value from the system call, it is a copy of its parent. At this point, its initialization is finished, and it's just like any other process in the virtual machine.

The other end of a process lifespan is fairly simple. The only resources that need to be cleaned up are some kmalloced buffers in the thread structure, which are freed, and the process in the host, which is killed.


next up previous
Next: System calls Up: Design and implementation Previous: Virtual machine initialization and
Jeff Dike 2000-08-23