OrionUserland
Barry Importing existing Orion Userland 19aefaa (3 years, 3 months ago)
diff --git a/time/main.c b/time/main.c
new file mode 100644
index 0000000..89ef9ab
--- /dev/null
+++ b/time/main.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/times.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+/* Main function */
+int
+main(int argc, char *argv[])
+{
+ pid_t pid;
+ Times tms;
+ clock_t r0, r1;
+ int status, ret = 0;
+
+ if (argc < 2)
+ return 0;
+
+ r0 = times(&tms);
+
+ pid = fork();
+ if (!pid) {
+ execv(argv[1], argv + 1);
+ printf("exec: %s: ", argv[1]);
+ perror(NULL);
+ exit(EXIT_FAILURE);
+ }
+ waitpid(pid, &status, 0);
+
+ if ((r1 = times(&tms)) == (clock_t) -1) {
+ perror("times");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("\nreal %dms\nuser %dms\nsys %dms\n",
+ (r1 - r0), tms.cutime, tms.cstime);
+// printf("\nreal %f\nuser %f\nsys %f\n",
+// (r1 - r0) / (double) 1000,
+// tms.cutime / (double) 1000,
+// tms.cstime / (double) 1000);
+
+ return 0;
+}