Luna/apps/src/init.c

42 lines
675 B
C
Raw Normal View History

#include <luna.h>
#include <stdio.h>
#include <sys/wait.h>
2022-10-02 17:25:56 +02:00
#include <unistd.h>
int main()
{
if (getpid() != 1)
2022-10-02 17:25:56 +02:00
{
fprintf(stderr, "init should be started as PID 1\n");
return 1;
2022-10-02 17:25:56 +02:00
}
printf("Welcome to Luna!\n\n");
2022-10-02 17:25:56 +02:00
2022-10-19 20:36:27 +02:00
msleep(200);
pid_t child = fork();
if (child < 0)
{
perror("fork");
return 1;
}
if (child == 0)
{
2022-10-19 19:42:05 +02:00
execv("/bin/sh", NULL);
perror("execv");
return 1;
}
2022-10-17 21:22:18 +02:00
pid_t result;
for (;;)
{
while ((result = wait(NULL)) == 0) // No child has exited yet
{
msleep(100);
}
if (result == child) { return 0; }
}
2022-10-02 17:25:56 +02:00
}