Luna/libos/src/Process.cpp

28 lines
680 B
C++
Raw Normal View History

2023-04-18 16:16:24 +00:00
#include <os/Process.h>
2023-04-18 16:39:37 +00:00
#include <errno.h>
2023-04-18 16:16:24 +00:00
#include <sys/syscall.h>
#include <unistd.h>
namespace os
{
Result<pid_t> Process::fork()
{
long rc = syscall(SYS_fork);
return Result<pid_t>::from_syscall(rc);
}
2023-04-18 16:39:37 +00:00
Result<void> Process::exec(StringView path, Slice<String> args, bool search_in_path)
{
Vector<const char*> argv;
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
TRY(argv.try_append(nullptr));
if (search_in_path) execvp(path.chars(), const_cast<char**>(argv.data()));
else
execv(path.chars(), const_cast<char**>(argv.data()));
return err(errno);
}
2023-04-18 16:16:24 +00:00
}