[fpc-pascal]how to find out if a TProcess was killed
Michael Van Canneyt
michael.vancanneyt at wisa.be
Tue May 27 14:17:02 CEST 2003
On Tue, 27 May 2003, Mattias Gaertner wrote:
> Hi,
>
> If I start a TProcess and the process is being killed by the system (for
> example, because it runs amok and allocates too much mem) the ExitStatus is
> 0. How can I find out, that the program was killed?
The exit status are the high bits of a word describing
how a process exited. The Wifsignaled function tells you whether the
process was signaled, and wtermsig tells you what signal caused the
exit. TProcess (being cross-platform) doesn't support this.
Here are the relevant functions (unit unix, 1.1 branch):
function WEXITSTATUS(Status: Integer): Integer;
begin
WEXITSTATUS:=(Status and $FF00) shr 8;
end;
function WTERMSIG(Status: Integer): Integer;
begin
WTERMSIG:=(Status and $7F);
end;
function WSTOPSIG(Status: Integer): Integer;
begin
WSTOPSIG:=WEXITSTATUS(Status);
end;
Function WIFEXITED(Status: Integer): Boolean;
begin
WIFEXITED:=(WTERMSIG(Status)=0);
end;
Function WIFSTOPPED(Status: Integer): Boolean;
begin
WIFSTOPPED:=((Status and $FF)=$7F);
end;
Function WIFSIGNALED(Status: Integer): Boolean;
begin
WIFSIGNALED:=(not WIFSTOPPED(Status)) and
(not WIFEXITED(Status));
end;
Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
begin
W_EXITCODE:=(ReturnCode shl 8) or Signal;
end;
Function W_STOPCODE(Signal: Integer): Integer;
begin
W_STOPCODE:=(Signal shl 8) or $7F;
end;
If you have suggestions for adding support for these functions
to TProcess, let me know.
Michael.
More information about the fpc-pascal
mailing list