function spawn( cmd, script, clbk ) {
	var child;
	var args;
	var opts;
	var err;

	debug( 'Creating child process...' );
	args = [ script ];
	opts = {
		'cwd': cwd(),
		'env': proc.env,
		'shell': false, // don't run the command inside a shell
		'stdio': 'inherit' // use stdio of worker process
	};
	if ( proc.env.WORKER_UID ) {
		opts.uid = parseInt( proc.env.WORKER_UID, 10 );
	}
	if ( proc.env.WORKER_GID ) {
		opts.gid = parseInt( proc.env.WORKER_GID, 10 );
	}
	child = run( cmd, args, opts );

	child.on( 'error', onError );
	child.on( 'close', onClose );
	child.on( 'exit', onExit );
	child.on( 'disconnect', onDisconnect );

	debug( 'Child process created. pid: %d.', child.pid );
	return child;

	/**
	* Callback invoked upon child process close.
	*
	* @private
	* @param {(number|null)} code - exit code
	* @param {(string|null)} signal - termination signal
	* @returns {void}
	*/
	function onClose( code, signal ) {
		debug( 'Child process closed. Code: %d. Signal: %s. pid: %d.', code, signal, child.pid );
		processExit( code, signal );
		if ( err ) {
			return clbk( err );
		}
		clbk( null, child.pid, script );
	}

	/**
	* Callback invoked upon child process exit.
	*
	* @private
	* @param {(number|null)} code - exit code
	* @param {(string|null)} signal - termination signal
	*/
	function onExit( code, signal ) {
		debug( 'Child process exited. Code: %d. Signal: %s. pid: %d.', code, signal, child.pid );
		processExit( code, signal );
	}

	/**
	* Callback invoked upon child process disconnect.
	*
	* @private
	*/
	function onDisconnect() {
		debug( 'Child process disconnected. pid: %d.', child.pid );
	}

	/**
	* Callback invoked upon child process error.
	*
	* @private
	* @param {Error} error - error object
	*/
	function onError( error ) {
		debug( 'Child process error: %s. pid: %d.', error.message, child.pid );
		clbk( error );
	}

	/**
	* Processes process exit values and sets the `err` state.
	*
	* @private
	* @param {(number|null)} code - exit code
	* @param {(string|null)} signal - termination signal
	*/
	function processExit( code, signal ) {
		if ( err ) {
			return;
		}
		if ( code !== null && code !== 0 ) {
			err = new Error( cmd+' '+script+' failed with exit code: '+code+'.' );
		} else if ( signal !== null ) {
			err = new Error( cmd+' '+script+' failed due to termination signal: '+signal+'.' );
		}
		if ( err ) {
			err.code = code;
			err.signal = signal;
		}
	}
}
Runs a script by spawning a child process.

@private
@param {string} cmd - command to run
@param {string} script - script filepath
@param {Callback} clbk - callback to invoke after a child process closes
@returns {Process} child process