From b93fbcf09a174b559da9ef07d9bb698e93c04972 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 3 Dec 2018 12:04:46 -0800 Subject: [PATCH 1/8] add osproc.processID() --- lib/pure/osproc.nim | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) + From e7ab4817e255e8206660fe3d9f8edd29422aaf32 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 3 Dec 2018 12:46:32 -0800 Subject: [PATCH 2/8] fixup --- lib/pure/osproc.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 02aac5cbd..abe20e91a 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -161,7 +161,8 @@ proc processID*(p: Process): int {.rtl, extern: "nosp$1".} = proc processID*(): int = ## return current process ID when defined(windows): - proc GetCurrentProcessId(): int32 {.stdcall, dynlib: "kernel32", + type DWORD = uint32 + proc GetCurrentProcessId(): DWORD {.stdcall, dynlib: "kernel32", importc: "GetCurrentProcessId".} result = GetCurrentProcessId() else: From 0caab530fbe8341e4a680e9d7b1ea032c52a1152 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 3 Dec 2018 12:51:28 -0800 Subject: [PATCH 3/8] fixup --- lib/pure/osproc.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index abe20e91a..2bbcc0417 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -164,7 +164,7 @@ proc processID*(): int = type DWORD = uint32 proc GetCurrentProcessId(): DWORD {.stdcall, dynlib: "kernel32", importc: "GetCurrentProcessId".} - result = GetCurrentProcessId() + result = GetCurrentProcessId().int else: result = getpid() From af7d758cfc5361faec2a8110a9248b95439fac9e Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 3 Dec 2018 14:03:06 -0800 Subject: [PATCH 4/8] address comments --- lib/pure/os.nim | 9 +++++++++ lib/pure/osproc.nim | 14 ++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index e2dd872e8..143a62beb 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 processID*(): int = + ## 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 2bbcc0417..62c5b9d0b 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -15,7 +15,7 @@ include "system/inclrtl" import strutils, os, strtabs, streams, cpuinfo -export quoteShell, quoteShellWindows, quoteShellPosix +export quoteShell, quoteShellWindows, quoteShellPosix, processID when defined(windows): import winlean @@ -155,19 +155,9 @@ 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.processID()``. return p.id -proc processID*(): int = - ## return current process ID - when defined(windows): - type DWORD = uint32 - proc GetCurrentProcessId(): DWORD {.stdcall, dynlib: "kernel32", - importc: "GetCurrentProcessId".} - result = GetCurrentProcessId().int - 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. From 53147cc54610a9917c6838e2f66080288706748d Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 3 Dec 2018 14:25:04 -0800 Subject: [PATCH 5/8] fixup --- lib/pure/os.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 143a62beb..1f5e63528 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -2419,7 +2419,7 @@ proc isHidden*(path: string): bool {.noNimScript.} = let fileName = lastPathPart(path) result = len(fileName) >= 2 and fileName[0] == '.' and fileName != ".." -proc processID*(): int = +proc processID*(): int {.noNimScript.} = ## return current process ID. See also ``osproc.processID(p: Process)``. when defined(windows): proc GetCurrentProcessId(): DWORD {.stdcall, dynlib: "kernel32", From 0768d3ae38d3c6b4e8a3fb8c6f206b80bfd971be Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 3 Dec 2018 15:40:03 -0800 Subject: [PATCH 6/8] fixup --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 3ecc77614..d330819a0 100644 --- a/changelog.md +++ b/changelog.md @@ -91,6 +91,7 @@ proc enumToString*(enums: openArray[enum]): string = - Vm suport for float32<->int32 and float64<->int64 casts was added. - There is a new pragma block `noSideEffect` that works like the `gcsafe` pragma block. +- added os.processID() ### Language changes From c0a91970f2f0b363fa8a704a425a457e0b8bc0f5 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 4 Dec 2018 00:45:58 -0800 Subject: [PATCH 7/8] fixup --- lib/pure/osproc.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 62c5b9d0b..77b3d8dcd 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -15,7 +15,7 @@ include "system/inclrtl" import strutils, os, strtabs, streams, cpuinfo -export quoteShell, quoteShellWindows, quoteShellPosix, processID +export quoteShell, quoteShellWindows, quoteShellPosix when defined(windows): import winlean From e4850b7f1cac1f2111f2d0fdf976cf4531ef21a2 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 4 Dec 2018 02:51:27 -0800 Subject: [PATCH 8/8] address comments --- changelog.md | 2 +- lib/pure/os.nim | 2 +- lib/pure/osproc.nim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index d330819a0..b305dc3e6 100644 --- a/changelog.md +++ b/changelog.md @@ -91,7 +91,7 @@ proc enumToString*(enums: openArray[enum]): string = - Vm suport for float32<->int32 and float64<->int64 casts was added. - There is a new pragma block `noSideEffect` that works like the `gcsafe` pragma block. -- added os.processID() +- added os.getCurrentProcessId() ### Language changes diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 1f5e63528..533d8f350 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -2419,7 +2419,7 @@ proc isHidden*(path: string): bool {.noNimScript.} = let fileName = lastPathPart(path) result = len(fileName) >= 2 and fileName[0] == '.' and fileName != ".." -proc processID*(): int {.noNimScript.} = +proc getCurrentProcessId*(): int {.noNimScript.} = ## return current process ID. See also ``osproc.processID(p: Process)``. when defined(windows): proc GetCurrentProcessId(): DWORD {.stdcall, dynlib: "kernel32", diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 77b3d8dcd..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. See also ``os.processID()``. + ## returns `p`'s process ID. See also ``os.getCurrentProcessId()``. return p.id proc waitForExit*(p: Process, timeout: int = -1): int {.rtl,