diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-12-05 08:12:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-05 08:12:17 +0100 |
commit | d21529649746e68fd6f3f955627eda3ee0017534 (patch) | |
tree | f6b764ae9d9c855031a02649bcf90f8c63edd2ca /lib | |
parent | 88dcad7c011b71fe6376c1fab62ca815fd4f1b73 (diff) | |
parent | e4850b7f1cac1f2111f2d0fdf976cf4531ef21a2 (diff) | |
download | Nim-d21529649746e68fd6f3f955627eda3ee0017534.tar.gz |
Merge pull request #9846 from timotheecour/pr_getpid
add os.getCurrentProcessId()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/os.nim | 9 | ||||
-rw-r--r-- | lib/pure/osproc.nim | 3 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index e2dd872e8..533d8f350 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -2419,6 +2419,15 @@ proc isHidden*(path: string): bool {.noNimScript.} = let fileName = lastPathPart(path) result = len(fileName) >= 2 and fileName[0] == '.' and fileName != ".." +proc getCurrentProcessId*(): int {.noNimScript.} = + ## return current process ID. See also ``osproc.processID(p: Process)``. + when defined(windows): + proc GetCurrentProcessId(): DWORD {.stdcall, dynlib: "kernel32", + importc: "GetCurrentProcessId".} + result = GetCurrentProcessId().int + else: + result = getpid() + {.pop.} proc setLastModificationTime*(file: string, t: times.Time) {.noNimScript.} = diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index a9f37412f..b2239b9c5 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -155,7 +155,7 @@ proc running*(p: Process): bool {.rtl, extern: "nosp$1", tags: [].} ## Returns true iff the process `p` is still running. Returns immediately. proc processID*(p: Process): int {.rtl, extern: "nosp$1".} = - ## returns `p`'s process ID. + ## returns `p`'s process ID. See also ``os.getCurrentProcessId()``. return p.id proc waitForExit*(p: Process, timeout: int = -1): int {.rtl, @@ -1341,3 +1341,4 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = { result[1] = peekExitCode(p) if result[1] != -1: break close(p) + |