-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathtest_fork.c
More file actions
189 lines (181 loc) · 3.82 KB
/
test_fork.c
File metadata and controls
189 lines (181 loc) · 3.82 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "menu.h"
#define FONTSIZE 10
int PrintMenuOS()
{
int i, j;
char data_M[FONTSIZE][FONTSIZE] =
{
" ",
" * * ",
" *** *** ",
" * * * * ",
" * * * * ",
" * ** * ",
" * * ",
" * * ",
" * * ",
" "
};
char data_e[FONTSIZE][FONTSIZE] =
{
" ",
" ",
" ** ",
" * * ",
" * * ",
" ****** ",
" * ",
" * ",
" *** ",
" "
};
char data_n[FONTSIZE][FONTSIZE] =
{
" ",
" ",
" ** ",
" * * ",
" * * ",
" * * ",
" * * ",
" * * ",
" * * ",
" "
};
char data_u[FONTSIZE][FONTSIZE] =
{
" ",
" ",
" * * ",
" * * ",
" * * ",
" * * ",
" * * ",
" * ** ",
" ** * ",
" "
};
char data_O[FONTSIZE][FONTSIZE] =
{
" ",
" **** ",
" * * ",
" * * ",
" * * ",
" * * ",
" * * ",
" * * ",
" **** ",
" "
};
char data_S[FONTSIZE][FONTSIZE] =
{
" ",
" **** ",
" ** ",
" ** ",
" *** ",
" ** ",
" ** ",
" ** ",
" **** ",
" "
};
for(i=0; i<FONTSIZE; i++)
{
for(j=0; j<FONTSIZE; j++)
{
printf("%c", data_M[i][j]);
}
for(j=0; j<FONTSIZE; j++)
{
printf("%c", data_e[i][j]);
}
for(j=0; j<FONTSIZE; j++)
{
printf("%c", data_n[i][j]);
}
for(j=0; j<FONTSIZE; j++)
{
printf("%c", data_u[i][j]);
}
for(j=0; j<FONTSIZE; j++)
{
printf("%c", data_O[i][j]);
}
for(j=0; j<FONTSIZE; j++)
{
printf("%c", data_S[i][j]);
}
printf("\n");
}
return 0;
}
int Quit(int argc, char *argv[])
{
/* add XXX clean ops */
}
int Time(int argc, char *argv[])
{
time_t tt;
struct tm *t;
tt = time(NULL);
t = localtime(&tt);
printf("time:%d:%d:%d:%d:%d:%d\n",t->tm_year+1900, t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
return 0;
}
int TimeAsm(int argc, char *argv[])
{
time_t tt;
struct tm *t;
asm volatile(
"mov $0,%%ebx\n\t"
"mov $0xd,%%eax\n\t"
"int $0x80\n\t"
"mov %%eax,%0\n\t"
: "=m" (tt)
);
t = localtime(&tt);
printf("time:%d:%d:%d:%d:%d:%d\n",t->tm_year+1900, t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
return 0;
}
int Fork(int argc, char *argv[])
{
int pid;
/* fork another process */
pid = fork();
if (pid<0)
{
/* error occurred */
fprintf(stderr,"Fork Failed!");
exit(-1);
}
else if (pid==0)
{
/* child process */
printf("This is Child Process!\n");
}
else
{
/* parent process */
printf("This is Parent Process!\n");
/* parent will wait for the child to complete*/
wait(NULL);
printf("Child Complete!\n");
}
}
int main()
{
PrintMenuOS();
SetPrompt("MenuOS>>");
MenuConfig("version","MenuOS V1.0(Based on Linux 3.18.6)",NULL);
MenuConfig("quit","Quit from MenuOS",Quit);
MenuConfig("time","Show System Time",Time);
MenuConfig("time-asm","Show System Time(asm)",TimeAsm);
MenuConfig("fork","Fork a new process",Fork);
ExecuteMenu();
}