Merge pull request #9846 from timotheecour/pr_getpid
add os.getCurrentProcessId()
This commit is contained in:
commit
d215296497
3 changed files with 12 additions and 1 deletions
|
|
@ -91,6 +91,7 @@ proc enumToString*(enums: openArray[enum]): string =
|
||||||
- Vm suport for float32<->int32 and float64<->int64 casts was added.
|
- Vm suport for float32<->int32 and float64<->int64 casts was added.
|
||||||
- There is a new pragma block `noSideEffect` that works like
|
- There is a new pragma block `noSideEffect` that works like
|
||||||
the `gcsafe` pragma block.
|
the `gcsafe` pragma block.
|
||||||
|
- added os.getCurrentProcessId()
|
||||||
|
|
||||||
### Language changes
|
### Language changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2419,6 +2419,15 @@ proc isHidden*(path: string): bool {.noNimScript.} =
|
||||||
let fileName = lastPathPart(path)
|
let fileName = lastPathPart(path)
|
||||||
result = len(fileName) >= 2 and fileName[0] == '.' and fileName != ".."
|
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.}
|
{.pop.}
|
||||||
|
|
||||||
proc setLastModificationTime*(file: string, t: times.Time) {.noNimScript.} =
|
proc setLastModificationTime*(file: string, t: times.Time) {.noNimScript.} =
|
||||||
|
|
|
||||||
|
|
@ -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.
|
## Returns true iff the process `p` is still running. Returns immediately.
|
||||||
|
|
||||||
proc processID*(p: Process): int {.rtl, extern: "nosp$1".} =
|
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
|
return p.id
|
||||||
|
|
||||||
proc waitForExit*(p: Process, timeout: int = -1): int {.rtl,
|
proc waitForExit*(p: Process, timeout: int = -1): int {.rtl,
|
||||||
|
|
@ -1341,3 +1341,4 @@ proc execCmdEx*(command: string, options: set[ProcessOption] = {
|
||||||
result[1] = peekExitCode(p)
|
result[1] = peekExitCode(p)
|
||||||
if result[1] != -1: break
|
if result[1] != -1: break
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue