-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyshell.c
More file actions
executable file
·44 lines (43 loc) · 819 Bytes
/
myshell.c
File metadata and controls
executable file
·44 lines (43 loc) · 819 Bytes
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
/*
* Filename:myshell.c
T* Description: The main function of myshell
* Author: Xu Yuhao
* Created: 2014.7.30
*/
#include "myshell.h"
int main(void){
int should_run = 1; /* flag to determine when to exit program */
int i;
for(i = 0; i < MAXCHILD;i ++)
CHILDTABLE[i] = 0;
while (should_run)
{
printf("myshell>");
fflush(stdout);
/**
* After reading user input, the steps are:
*Inner command:
*…..
*Out command:
* (1) fork a child process using fork()
* (2) the child process will invoke execvp()
* (3) if command included &, parent will invoke wait()
*…..
*/
init_env();
print_CMD();
NUMBER_ARGS = get_args();
if(if_inner_cmd())
{
should_run = inner_pro();
}
else
{
if(NUMBER_ARGS > 1)
out_parse();
out_pro();
}
clean();
}
return 0;
}