How to reliably terminate a process

Hi, I am writing an application on Windows XP using ghc 6.10.1 that manages test cases (same applies to ghc 6.8.3). For each selected test case, the application runs an executable associated with the test case using System.Process.runInteractiveCommand. These processes have to be aborted in some cases, for example, when their specified termination time is up. As I realized, however, aborting these processes using terminateProcess is not reliable. Most often, the processes do not terminate correctly but have to be killed from the Windows Task Manager. In some cases, the process still produces output - in particular if I apply getProcessExitCode on the process just killed. By the way: calling and killing the process from the shell with Ctrl-C successfully kills the process. Any advice on how to reliably terminate a process on Windows? Thanks, Bernd

On Tue, Nov 25, 2008 at 10:09:15PM +0100, Bernd Holzmüller wrote:
Any advice on how to reliably terminate a process on Windows?
You can see how the timeout program in GHC's testsuite does this here: http://darcs.haskell.org/testsuite/timeout/timeout.hs Thanks Ian

Due to the way which runInteractiveCommand works (through spawning a shell), it is impossible to consistently terminate a process launched using it. If the process tries to read from stdin, then it will die properly -- however, last I checked, processes blocking on reading stdin from within runInteractiveCommand will cause bizarre memory leaks. runInteractiveProcess will work as you expect. For more information, see the bug report here: http://hackage.haskell.org/trac/ghc/ticket/2638 Regards, Sterl. On Tue, Nov 25, 2008 at 4:09 PM, Bernd Holzmüller < bernd.holzmueller@ics-ag.de> wrote:
Hi,
I am writing an application on Windows XP using ghc 6.10.1 that manages test cases (same applies to ghc 6.8.3). For each selected test case, the application runs an executable associated with the test case using System.Process.runInteractiveCommand. These processes have to be aborted in some cases, for example, when their specified termination time is up. As I realized, however, aborting these processes using terminateProcess is not reliable. Most often, the processes do not terminate correctly but have to be killed from the Windows Task Manager. In some cases, the process still produces output - in particular if I apply getProcessExitCode on the process just killed. By the way: calling and killing the process from the shell with Ctrl-C successfully kills the process.
Any advice on how to reliably terminate a process on Windows?
Thanks, Bernd _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Sterling Clover wrote:
Due to the way which runInteractiveCommand works (through spawning a shell), it is impossible to consistently terminate a process launched using it. If the process tries to read from stdin, then it will die properly -- however, last I checked, processes blocking on reading stdin from within runInteractiveCommand will cause bizarre memory leaks.
runInteractiveProcess will work as you expect.
The documentation for terminateProcess now includes this: -- Note: on Windows, if the process was a shell command created by -- 'createProcess' with 'shell', or created by 'runCommand' or -- 'runInteractiveCommand', then 'terminateProcess' will only -- terminate the shell, not the command itself. On Unix systems, both -- processes are in a process group and will be terminated together. Cheers, Simon
participants (4)
-
Bernd Holzmüller
-
Ian Lynagh
-
Simon Marlow
-
Sterling Clover