2014-02-13 18:00:15 +00:00
|
|
|
{- Windows processes
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-02-13 18:00:15 +00:00
|
|
|
-
|
2014-05-10 14:01:27 +00:00
|
|
|
- License: BSD-2-clause
|
2014-02-13 18:00:15 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE ForeignFunctionInterface #-}
|
|
|
|
|
|
|
|
module Utility.WinProcess where
|
|
|
|
|
|
|
|
import Utility.PID
|
|
|
|
|
2015-09-01 21:37:02 +00:00
|
|
|
import System.Win32.Process
|
|
|
|
import Control.Exception (bracket)
|
|
|
|
import Control.Monad
|
|
|
|
|
|
|
|
terminatePID :: PID -> IO ()
|
|
|
|
terminatePID p = bracket
|
|
|
|
(openProcess pROCESS_TERMINATE False p)
|
|
|
|
(void . c_closeProcess)
|
|
|
|
(\h -> void $ c_TerminateProcess h 1)
|
|
|
|
|
|
|
|
foreign import ccall unsafe "windows.h TerminateProcess"
|
|
|
|
c_TerminateProcess :: ProcessHandle -> Int -> IO Int
|
|
|
|
|
|
|
|
foreign import ccall unsafe "windows.h CloseHandle"
|
|
|
|
c_closeProcess :: ProcessHandle -> IO Bool
|