apio
140910763e
All checks were successful
Build and test / build (push) Successful in 1m56s
Why are command-line utilities stored in "apps"? And why are apps like "editor" or "terminal" top-level directories? Command-line utilities now go in "utils". GUI stuff now goes in "gui". This includes: libui -> gui/libui, wind -> gui/wind, GUI apps -> gui/apps, editor&terminal -> gui/apps... System services go in "system".
41 lines
1.0 KiB
C++
41 lines
1.0 KiB
C++
#include <os/ArgumentParser.h>
|
|
#include <os/File.h>
|
|
#include <os/Process.h>
|
|
#include <stdio.h>
|
|
#include <sys/resource.h>
|
|
|
|
Result<int> luna_main(int argc, char** argv)
|
|
{
|
|
Vector<StringView> command;
|
|
|
|
os::ArgumentParser parser;
|
|
parser.add_description("Time a command.");
|
|
parser.add_system_program_info("time"_sv);
|
|
parser.set_vector_argument(command, "command"_sv, true, true);
|
|
TRY(parser.parse(argc, argv));
|
|
|
|
auto pid = TRY(os::Process::fork());
|
|
|
|
if (pid == 0)
|
|
{
|
|
TRY(os::Process::exec(command[0], command.slice()));
|
|
unreachable();
|
|
}
|
|
|
|
TRY(os::Process::wait(pid, nullptr));
|
|
|
|
struct rusage usage;
|
|
if (getrusage(RUSAGE_CHILDREN, &usage) < 0)
|
|
{
|
|
perror("getrusage");
|
|
return 1;
|
|
}
|
|
|
|
auto cmdline = TRY(String::join(command, " "));
|
|
|
|
os::println("%s %ld.%.2lds user %ld.%.2lds system", cmdline.chars(), usage.ru_utime.tv_sec,
|
|
usage.ru_utime.tv_usec / 10000, usage.ru_stime.tv_sec, usage.ru_stime.tv_usec / 10000);
|
|
|
|
return 0;
|
|
}
|