[M3devel] platform-independent kill process

Mika Nystrom mika at async.caltech.edu
Sun Feb 20 17:54:00 CET 2011


While poking around the compiler sources I found something called
M3Process.Interrupt in m3middle---note the comment about Win32:

PROCEDURE Interrupt (t: Process.T)  RAISES {OSError.E};
(* Send an interrupt signal to process 't'.  *)

PROCEDURE Abort (t: Process.T)  RAISES {OSError.E};
(* Make a best effort attempt to stop process 't'.   Warning: aborting a
   process may leave it in a broken state or fail to release its OS
   resources (ie. Win32 is broken!)  *)

POSIX implementation:

PROCEDURE Interrupt (t: Process.T)  RAISES {OSError.E} =
  VAR pid := Process.GetID (t);
  BEGIN
    IF Usignal.kill (pid, Usignal.SIGINT) # 0 THEN
      OSErrorPosix.Raise ();
    END;
  END Interrupt;

PROCEDURE Abort (t: Process.T)  RAISES {OSError.E} =
  VAR pid := Process.GetID (t);
  BEGIN
    IF Usignal.kill (pid, Usignal.SIGKILL) # 0 THEN
      OSErrorPosix.Raise ();
    END;
  END Abort;

WIN32:

PROCEDURE Interrupt (t: Process.T)  RAISES {OSError.E} =
  BEGIN
    Abort (t); (* can't do any better yet... *)
  END Interrupt;


PROCEDURE Abort (t: Process.T)  RAISES {OSError.E} =
  VAR hProcess := LOOPHOLE (Process.GetID (t), WinNT.HANDLE);
  BEGIN
    IF WinBase.TerminateProcess (hProcess, 1) = 0 THEN
      OSErrorWin32.Raise ();
    END;
  END Abort;

I don't know enough about Windows to deciper the warning about releasing
resources...

     Mika


Olaf Wagner writes:
>I've been thinking a bit about the hanging tests problem in our regression
>test framework. I'd like to provide a simple utility to start a program
>with time supervision. But as far as I can see, Modula-3 does not provide
>a platform-independent way of terminating a process. Of course, on Unix
>I can send signals; but what would I do on Windows? A quick scan of the
>win32 interfaces in m3core hasn't brought up anything, but I might
>have looked for the wrong texts.
>
>Could we easily extend the Process interface e.g. by
>
>   PROCEDURE Terminate( p: T ): ExitCode RAISES TerminationException
>
>?
>Any opinions about that? Different interface suggestions?
>Rather create ProcessExtras than extending a `standard' interface?
>
>We currently only have to consider Unix and Windows, or are there
>other active flavours of OSs to care for?
>
>Olaf
>--=20
>Olaf Wagner -- elego Software Solutions GmbH
>                Gustav-Meyer-Allee 25 / Geb=E4ude 12, 13355 Berlin, Germany
>phone: +49 30 23 45 86 96  mobile: +49 177 2345 869  fax: +49 30 23 45 86 95
>    http://www.elegosoft.com | Gesch=E4ftsf=FChrer: Olaf Wagner | Sitz: Berl=
>in
>Handelregister: Amtsgericht Charlottenburg HRB 77719 | USt-IdNr: DE163214194



More information about the M3devel mailing list