Usage

How to compile

make

test

python2 test/tester.py

workflow

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]
Loading

Notes

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);

Reference

char s[]和char *s,兩者有什麼差異呢

strcpy & strncpy

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

strsep

execvp

chdir

close

wait() hang

Having trouble with fork(), pipe(), dup2() and exec() in C

Having trouble connecting multiple pipes together

Implementation of multiple pipes in C

loyola college