summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2018-12-03 12:04:46 -0800
committerTimothee Cour <timothee.cour2@gmail.com>2018-12-03 12:04:46 -0800
commitb93fbcf09a174b559da9ef07d9bb698e93c04972 (patch)
tree79e9ec52774caa292540809feec899e4f47b2b57 /lib
parentf86b827d9e10f0178f1bb89d1c7df8c6b7b7eba0 (diff)
downloadNim-b93fbcf09a174b559da9ef07d9bb698e93c04972.tar.gz
add osproc.processID()
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/osproc.nim10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index a9f37412f..02aac5cbd 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -158,6 +158,15 @@ proc processID*(p: Process): int {.rtl, extern: "nosp$1".} =
   ## returns `p`'s process ID.
   return p.id
 
+proc processID*(): int =
+  ## return current process ID
+  when defined(windows):
+    proc GetCurrentProcessId(): int32 {.stdcall, dynlib: "kernel32",
+                                        importc: "GetCurrentProcessId".}
+    result = GetCurrentProcessId()
+  else:
+    result = getpid()
+
 proc waitForExit*(p: Process, timeout: int = -1): int {.rtl,
   extern: "nosp$1", tags: [].}
   ## waits for the process to finish and returns `p`'s error code.
@@ -1341,3 +1350,4 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = {
       result[1] = peekExitCode(p)
       if result[1] != -1: break
   close(p)
+