Ejemplo n.º 1
0
/**
	process_kill : 'process -> void
	<doc>
	Terminates a running process.
	</doc>
**/
static value process_kill( value vp ) {
	val_check_kind(vp,k_process);
#	ifdef NEKO_WINDOWS
	TerminateProcess(val_process(vp)->pinf.hProcess,-1);
#	else
	kill(val_process(vp)->pid,9);
#	endif
	return val_null;
}
Ejemplo n.º 2
0
/**
	process_kill : 'process -> void
	<doc>
	Terminates a running process.
	</doc>
**/
CAMLprim value process_kill( value vp ) {
	val_check_kind(vp,k_process);
#	ifdef _WIN32
	TerminateProcess(val_process(vp)->pinf.hProcess,-1);
#	else
	kill(val_process(vp)->pid,9);
#	endif
	return val_null;
}
Ejemplo n.º 3
0
/**
	process_exit : 'process -> int
	<doc>
	Wait until the process terminate, then returns its exit code.
	</doc>
**/
static value process_exit( value vp ) {
	vprocess *p;
	val_check_kind(vp,k_process);
	p = val_process(vp);
#	ifdef NEKO_WINDOWS
	{
		DWORD rval;
		WaitForSingleObject(p->pinf.hProcess,INFINITE);
		if( !GetExitCodeProcess(p->pinf.hProcess,&rval) )
			neko_error();
		return alloc_int(rval);
	}
#	else
	int rval;
	while( waitpid(p->pid,&rval,0) != p->pid ) {
		if( errno == EINTR )
			continue;
		neko_error();
	}
	if( !WIFEXITED(rval) ) {
		if (WIFSIGNALED(rval)) {
			char msg[30];
			sprintf(msg, "process killed by signal %d", WTERMSIG(rval));
			val_throw(alloc_string(msg));
		} else {
			neko_error();
		}
	}
	return alloc_int(WEXITSTATUS(rval));
#	endif
}
Ejemplo n.º 4
0
/**
   process_exit : 'process -> int
   <doc>
   Wait until the process terminate, then returns its exit code.
   </doc>
**/
static value process_exit( value vp ) {
   vprocess *p;
   val_check_kind(vp,k_process);
   p = val_process(vp);
   gc_enter_blocking();
#   ifdef NEKO_WINDOWS
   {
      DWORD rval;
      WaitForSingleObject(p->pinf.hProcess,INFINITE);
      gc_exit_blocking();
      if( !GetExitCodeProcess(p->pinf.hProcess,&rval) )
         return alloc_null();
      return alloc_int(rval);
   }
#   else
   int rval;
   while( waitpid(p->pid,&rval,0) != p->pid ) {
      if( errno == EINTR )
         continue;
      gc_exit_blocking();
      return alloc_null();
   }
   gc_exit_blocking();
   if( !WIFEXITED(rval) )
      return alloc_null();
   return alloc_int(WEXITSTATUS(rval));
#   endif
}
Ejemplo n.º 5
0
/**
	process_pid : 'process -> int
	<doc>
	Returns the process id.
	</doc>
**/
static value process_pid( value vp ) {
	vprocess *p;
	val_check_kind(vp,k_process);
	p = val_process(vp);
#	ifdef NEKO_WINDOWS
	return alloc_int(p->pinf.dwProcessId);
#	else
	return alloc_int(p->pid);
#	endif
}
Ejemplo n.º 6
0
/**
	process_pid : 'process -> int
	<doc>
	Returns the process id.
	</doc>
**/
CAMLprim value process_pid( value vp ) {
	vprocess *p;
	val_check_kind(vp,k_process);
	p = val_process(vp);
#	ifdef _WIN32
	return alloc_int(p->pinf.dwProcessId);
#	else
	return alloc_int(p->pid);
#	endif
}
Ejemplo n.º 7
0
static void free_process( value vp ) {
	vprocess *p = val_process(vp);
#	ifdef NEKO_WINDOWS
	CloseHandle(p->eread);
	CloseHandle(p->oread);
	CloseHandle(p->iwrite);
	CloseHandle(p->pinf.hProcess);
	CloseHandle(p->pinf.hThread);
#	else
	do_close(p->eread);
	do_close(p->oread);
	do_close(p->iwrite);
#	endif
}
Ejemplo n.º 8
0
/**
	process_stdin_close : 'process -> void
	<doc>
	Close the process standard input.
	</doc>
**/
static value process_stdin_close( value vp ) {
	vprocess *p;
	val_check_kind(vp,k_process);
	p = val_process(vp);
#	ifdef NEKO_WINDOWS
	if( !CloseHandle(p->iwrite) )
		neko_error();
#	else
	if( do_close(p->iwrite) )
		neko_error();
	p->iwrite = -1;
#	endif
	return val_null;
}
Ejemplo n.º 9
0
/**
	process_exit : 'process -> int
	<doc>
	Wait until the process terminate, then returns its exit code.
	</doc>
**/
CAMLprim value process_exit( value vp ) {
	vprocess *p;
	val_check_kind(vp,k_process);
	p = val_process(vp);
#	ifdef _WIN32
	{
		DWORD rval;
		WaitForSingleObject(p->pinf.hProcess,INFINITE);
		if( !GetExitCodeProcess(p->pinf.hProcess,&rval) )
			neko_error();
		return alloc_int(rval);
	}
#	else
	int rval;
	while( waitpid(p->pid,&rval,0) != p->pid ) {
		if( errno == EINTR )
			continue;
		neko_error();
	}
	if( !WIFEXITED(rval) )
		neko_error();
	return alloc_int(WEXITSTATUS(rval));
#	endif
}