libos: Add a Process class
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
fbb7de7156
commit
6ce125d286
@ -3,6 +3,7 @@
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <os/File.h>
|
||||
#include <os/FileSystem.h>
|
||||
#include <os/Process.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
@ -113,12 +114,7 @@ Result<int> luna_main(int argc, char** argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
pid_t child = fork();
|
||||
if (child < 0)
|
||||
{
|
||||
perror("fork");
|
||||
return 1;
|
||||
}
|
||||
pid_t child = TRY(os::Process::fork());
|
||||
|
||||
if (child == 0) { execute_command(cmd.view()); }
|
||||
|
||||
|
@ -7,6 +7,7 @@ set(SOURCES
|
||||
src/ArgumentParser.cpp
|
||||
src/File.cpp
|
||||
src/FileSystem.cpp
|
||||
src/Process.cpp
|
||||
src/Main.cpp
|
||||
)
|
||||
|
||||
|
12
libos/include/os/Process.h
Normal file
12
libos/include/os/Process.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include <luna/Result.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace os
|
||||
{
|
||||
class Process
|
||||
{
|
||||
public:
|
||||
static Result<pid_t> fork();
|
||||
};
|
||||
}
|
12
libos/src/Process.cpp
Normal file
12
libos/src/Process.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <os/Process.h>
|
||||
#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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user