aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-04-06 09:03:52 +0100
committerRon Yorston <rmy@pobox.com>2020-04-06 09:03:52 +0100
commit9181e1363f09f80ba822175886450b751e408f14 (patch)
tree000415bab289dd387e9217db9c1da7b0c2bf8549 /win32
parent4ecfc9fc115221ec66769915bf02ac37c40ffcd5 (diff)
downloadbusybox-w32-9181e1363f09f80ba822175886450b751e408f14.tar.gz
busybox-w32-9181e1363f09f80ba822175886450b751e408f14.tar.bz2
busybox-w32-9181e1363f09f80ba822175886450b751e408f14.zip
time: WIN32 port
Port the time applet to WIN32. This requires the implemntation of a replacement for wait3(2). Only elapsed, user and system times are supported, not the memory and i/o statistics reported by GNU time.
Diffstat (limited to 'win32')
-rw-r--r--win32/process.c41
-rw-r--r--win32/sys/resource.h11
2 files changed, 45 insertions, 7 deletions
diff --git a/win32/process.c b/win32/process.c
index 67ce3c100..28df33c23 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -3,21 +3,48 @@
3#include <psapi.h> 3#include <psapi.h>
4#include "lazyload.h" 4#include "lazyload.h"
5 5
6int waitpid(pid_t pid, int *status, int options) 6pid_t waitpid(pid_t pid, int *status, int options)
7#if ENABLE_TIME
8{
9 return mingw_wait3(pid, status, options, NULL);
10}
11#endif
12
13#if ENABLE_TIME
14pid_t mingw_wait3(pid_t pid, int *status, int options, struct rusage *rusage)
15#endif
7{ 16{
8 HANDLE proc; 17 HANDLE proc;
9 intptr_t ret; 18 DWORD code;
10 19
11 /* Windows does not understand parent-child */ 20 /* Windows does not understand parent-child */
12 if (pid > 0 && options == 0) { 21 if (pid > 0 && options == 0) {
13 if ( (proc=OpenProcess(SYNCHRONIZE|PROCESS_QUERY_INFORMATION, 22 if ( (proc=OpenProcess(SYNCHRONIZE|PROCESS_QUERY_INFORMATION,
14 FALSE, pid)) != NULL ) { 23 FALSE, pid)) != NULL ) {
15 ret = _cwait(status, (intptr_t)proc, 0); 24 WaitForSingleObject(proc, INFINITE);
16 CloseHandle(proc); 25 GetExitCodeProcess(proc, &code);
17 if (ret == -1) { 26#if ENABLE_TIME
18 return -1; 27 if (rusage != NULL) {
28 FILETIME crTime, exTime, keTime, usTime;
29
30 memset(rusage, 0, sizeof(*rusage));
31 if (GetProcessTimes(proc, &crTime, &exTime, &keTime, &usTime)) {
32 uint64_t kernel_usec =
33 (((uint64_t)keTime.dwHighDateTime << 32)
34 | (uint64_t)keTime.dwLowDateTime)/10;
35 uint64_t user_usec =
36 (((uint64_t)usTime.dwHighDateTime << 32)
37 | (uint64_t)usTime.dwLowDateTime)/10;
38
39 rusage->ru_utime.tv_sec = user_usec / 1000000U;
40 rusage->ru_utime.tv_usec = user_usec % 1000000U;
41 rusage->ru_stime.tv_sec = kernel_usec / 1000000U;
42 rusage->ru_stime.tv_usec = kernel_usec % 1000000U;
43 }
19 } 44 }
20 *status <<= 8; 45#endif
46 CloseHandle(proc);
47 *status = code << 8;
21 return pid; 48 return pid;
22 } 49 }
23 } 50 }
diff --git a/win32/sys/resource.h b/win32/sys/resource.h
index e69de29bb..3220d8112 100644
--- a/win32/sys/resource.h
+++ b/win32/sys/resource.h
@@ -0,0 +1,11 @@
1#ifndef _SYS_RESOURCE_H
2#define _SYS_RESOURCE_H 1
3
4#include <time.h>
5
6struct rusage {
7 struct timeval ru_utime;
8 struct timeval ru_stime;
9};
10
11#endif