libc: Add fork()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-18 23:58:56 +01:00
parent 54f2d35416
commit 40f01c825d
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 10 additions and 3 deletions

View File

@ -37,12 +37,12 @@ int main()
fprintf(stderr, "init is running as PID %d\n", getpid());
long ret = syscall(SYS_fork);
pid_t ret = fork();
if (ret == 0)
{
char* argv[] = { "/bin/hello", "--help", NULL };
execv("/bin/hello", argv);
}
else { printf("my child is PID %ld!\n", ret); }
else { printf("my child is PID %d!\n", ret); }
}

View File

@ -18,7 +18,8 @@ extern "C"
{
#endif
pid_t fork();
/* Create a new process that is a clone of the current one. */
pid_t fork(void);
/* Return the current process' process ID. */
pid_t getpid(void);

View File

@ -8,6 +8,12 @@ extern "C" long arch_invoke_syscall(long, uintptr_t, uintptr_t, uintptr_t, uintp
extern "C"
{
pid_t fork(void)
{
long rc = syscall(SYS_fork);
__errno_return(rc, int);
}
pid_t getpid(void)
{
return (pid_t)syscall(SYS_getpid);