Convert from forking to threading for process control