summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorSimon Krauter <krauter.simon@arcor.de>2014-11-02 03:00:47 +0100
committerSimon Krauter <krauter.simon@arcor.de>2014-11-02 03:00:47 +0100
commitf3d7158d5db591a88a6da3234a1f72d534c543fb (patch)
tree4b1874bad2e547d8626183683a245d29ff83a009 /lib/pure
parenteaa5a2599fee7f7fc3482b120868b700b4b1a721 (diff)
downloadNim-f3d7158d5db591a88a6da3234a1f72d534c543fb.tar.gz
Fix terminate() and add kill()
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/osproc.nim22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index 3c181bf53..4384cd7d2 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -164,8 +164,11 @@ proc resume*(p: PProcess) {.rtl, extern: "nosp$1", tags: [].}
   ## Resumes the process `p`.
 
 proc terminate*(p: PProcess) {.rtl, extern: "nosp$1", tags: [].}
-  ## Terminates the process `p`.
+  ## Stop the process `p`. On Posix OSs the procedure sends SIGTERM to the process. On Windows the Win32 API function TerminateProcess() is called to stop the process.
 
+proc kill*(p: PProcess) {.rtl, extern: "nosp$1", tags: [].}
+  ## Kill the process `p`. On Posix OSs the procedure sends SIGKILL to the process. On Windows kill() is an alias for terminate().
+  
 proc running*(p: PProcess): bool {.rtl, extern: "nosp$1", tags: [].}
   ## Returns true iff the process `p` is still running. Returns immediately.
 
@@ -475,6 +478,9 @@ when defined(Windows) and not defined(useNimRtl):
     if running(p):
       discard terminateProcess(p.fProcessHandle, 0)
 
+  proc kill(p: PProcess) =
+    terminate(p)
+      
   proc waitForExit(p: PProcess, timeout: int = -1): int =
     discard waitForSingleObject(p.fProcessHandle, timeout.int32)
 
@@ -815,10 +821,10 @@ elif not defined(useNimRtl):
     discard close(p.errHandle)
 
   proc suspend(p: PProcess) =
-    if kill(-p.id, SIGSTOP) != 0'i32: osError(osLastError())
+    if kill(p.id, SIGSTOP) != 0'i32: osError(osLastError())
 
   proc resume(p: PProcess) =
-    if kill(-p.id, SIGCONT) != 0'i32: osError(osLastError())
+    if kill(p.id, SIGCONT) != 0'i32: osError(osLastError())
 
   proc running(p: PProcess): bool =
     var ret = waitpid(p.id, p.exitCode, WNOHANG)
@@ -826,11 +832,13 @@ elif not defined(useNimRtl):
     result = ret == int(p.id)
 
   proc terminate(p: PProcess) =
-    if kill(-p.id, SIGTERM) == 0'i32:
-      if p.running():
-        if kill(-p.id, SIGKILL) != 0'i32: osError(osLastError())
-    else: osError(osLastError())
+    if kill(p.id, SIGTERM) != 0'i32:
+      osError(osLastError())
 
+  proc kill(p: PProcess) =
+    if kill(p.id, SIGKILL) != 0'i32: 
+      osError(osLastError())
+    
   proc waitForExit(p: PProcess, timeout: int = -1): int =
     #if waitPid(p.id, p.exitCode, 0) == int(p.id):
     # ``waitPid`` fails if the process is not running anymore. But then