How to compile
make
test
python2 test/tester.py
All the codes are in the file shell.c
graph LR
A[read input] --> C{command contain pipe}
C -->|pipe| D[create pipe]
D --> H[handle each command & pipe]
C -->|no pipe| E{custom command}
E -->|yes| F[use custom command handler to handle]
E -->|no| G[fork & execvp]
difference between char s[] & char* s
char s[] = "Hello world"; // s is a constant, s always = &s[0]
char *s = "Hello world"; // s is a variable, can use *s++ -> s取值後加加
while(*s)
printf("%c", *s++);
malloc
char* buffer = (char *)malloc(10 * sizeof(char)); //malloc return a void *
dup2
int dup2(int oldfd, int newfd);
getline // As the getline reads data, it will automatically reallocate more memory for the string variable as needed.
Why do we cast return value of malloc
Having trouble with fork(), pipe(), dup2() and exec() in C
Having trouble connecting multiple pipes together