On 05/04/2010 01:58 AM, Lars T. Kyllingstad wrote:


In your case the segfault would cause SIGSEGV (signal 11) to be sent to
the process, and the the above test would print "Process terminated by
signal 11".

See "man wait" for more info.

That's where I got my info (or rather /usr/include/bits/waitstatus.h)



std.process is currently undergoing a complete redesign, so the current
situation should improve in the near future. :)

-Lars

That's good to hear. And since you're an expert in this stuff, does this my code look alright?

import std.typecons;
static import std.c.process;
import std.functional;
import std.stdio;
import std.string;

alias Tuple!(ubyte, "status",ubyte, "term", ubyte, "sig",bool,"signaled",bool, "stopped", bool,"continued",bool, "coredumped") PID;

PID toPID(int p){
    PID pid;
    pid.status = cast(byte)((p & 0xff00) >> 8);
    pid.term = cast(byte)(p & 0xff);
    pid.sig = cast(byte)(p & 0x7f);
    pid.signaled = pid.sig != 0 && pid.sig != 0x7f;
    pid.coredumped = cast(bool)(p & 0x80);
    pid.stopped = pid.term == 0x7f;
    pid.continued = p == 0xffff;
    return pid;
}

int fromPID(PID pid){
    if(pid.signaled) return pid.term;
    return pid.status;
}

alias compose!(toPID, std.c.process.system, toStringz) system_p;
alias compose!(fromPID, system_p) system;

Reply via email to