blob: 827a21e397388ce217e167b849da6ff66d30f090 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include "ulib/stdio.h"
#include "ulib/stdlib.h"
#include "ulib/string.h"
#include "user/user.h"
int main()
{
char *argv[] = {(char *)"sh", 0};
printf("[Init] Starting Lume OS Shell...\n");
while (1)
{
// printf("fork start\n");
int pid = fork();
// printf("fork suceess, pid=%i\n", pid);
if (pid < 0)
{
printf("[Init] fork failed!\n");
exit(1);
}
if (pid == 0)
{
char sh_path[] = "/sh";
exec(sh_path, argv);
printf("[Init] exec sh failed\n");
return 0;
exit(1);
}
else
{
// break;
int status;
int wpid;
while (1)
{
wpid = wait((uint64)&status);
if (wpid == pid)
{
printf("Shell Exit");
break;
}
if (wpid < 0)
{
printf("[Init] wait error or no child\n");
break;
}
}
}
}
return 0;
}
|