TProcess ExitStatus is zero when the called process Seg Faults
Original Reporter info from Mantis: dhandy
-
Reporter name:
Original Reporter info from Mantis: dhandy
- Reporter name:
Description:
A program that seg faults returns an exit code of 139. When executing a process that seg faults with a TProcess, the exit code is returned as 0.
Steps to reproduce:
First, create a simple program that will seg fault every time. A simple C program that will do this is:
-------------------------------------
#include &LtPos;stdio.h>
#include &LtPos;stdlib.h>
#include &LtPos;stddef.h>
main()
{
printf("before C main program access violation\n");
int *c = NULL;
*c = 1;
printf("after C main program access violation\n");
}
-------------------------------------
Compile the C program and execute it directly. It will seg fault, and looking at the exit code by executing "echo $?" immediately after will show an exit code of 139. Then, execute the program as a TProcess like this (where 'MakeSegFault' is the name of the compiled program above):
-------------------------------------
program ProcessTest;
{$mode objfpc}{$H+}
uses
cthreads,
Classes,
sysutils,
process;
{$R *.res}
var
proc : TProcess;
begin
proc := TProcess.Create(nil);
try
proc.CommandLine := 'MakeSegFault';
proc.Execute;
while proc.Running do begin
sleep(1000);
end;
WriteLn('TProcess exit code: ' + IntToStr(proc.ExitStatus));
finally
proc.Free;
end;
end.
-------------------------------------
The exit code will be 0.
Mantis conversion info:
- Mantis ID: 22055
- OS: Linux/Ubuntu
- OS Build: 11.04
- Platform: x86_64
- Version: 2.6.0
- Fixed in version: 3.0.0
- Fixed in revision: 26706 (#8a4e0e6e).
- Target version: 3.0.0