diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | lib/posix/posix.nim | 20 |
2 files changed, 22 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md index 85e06112b..9382a194f 100644 --- a/changelog.md +++ b/changelog.md @@ -124,6 +124,8 @@ proc enumToString*(enums: openArray[enum]): string = - Added `xmltree.toXmlAttributes`. +- Added `Rusage`, `getrusage`, `wait4` to posix interface. + ### Library changes diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index 175f6a61d..800188b8f 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -663,6 +663,26 @@ proc waitid*(a1: cint, a2: Id, a3: var SigInfo, a4: cint): cint {. proc waitpid*(a1: Pid, a2: var cint, a3: cint): Pid {. importc, header: "<sys/wait.h>".} +type Rusage* {.importc: "struct rusage", header: "<sys/resource.h>", + bycopy.} = object + ru_utime*, ru_stime*: Timeval # User and system time + ru_maxrss*, ru_ixrss*, ru_idrss*, ru_isrss*, # memory sizes + ru_minflt*, ru_majflt*, ru_nswap*, # paging activity + ru_inblock*, ru_oublock*, ru_msgsnd*, ru_msgrcv*, # IO activity + ru_nsignals*, ru_nvcsw*, ru_nivcsw*: clong # switching activity + +proc wait4*(pid: Pid, status: ptr cint, options: cint, rusage: ptr Rusage): Pid + {.importc, header: "<sys/wait.h>".} + +const + RUSAGE_SELF* = cint(0) + RUSAGE_CHILDREN* = cint(-1) + RUSAGE_THREAD* = cint(1) # This one is less std; Linux, BSD agree though. + +# This can only fail if `who` is invalid or `rusage` ptr is invalid. +proc getrusage*(who: cint, rusage: ptr Rusage): cint + {.importc, header: "<sys/resource.h>", discardable.} + proc bsd_signal*(a1: cint, a2: proc (x: pointer) {.noconv.}) {. importc, header: "<signal.h>".} proc kill*(a1: Pid, a2: cint): cint {.importc, header: "<signal.h>".} |