# 2021-04-06 `robertlin0401`
contributed by < `robertlin0401` >
###### tags: `linux2021`
> [2021 年第 7 週測驗題](https://hackmd.io/@sysprog/linux2021-quiz7)
> [github repository](https://github.com/robertlin0401/Linux-Kernel-Internals-quiz7)
---
## [測驗一](https://hackmd.io/@sysprog/H1l5yStSu)
```c=50
char *redir_stdin = NULL, *redir_stdout = NULL;
int pipefds[2] = {0, 0}, outfd = 0;
char *v[99] = {0};
char **u = &v[98]; /* end of words */
for (;;) {
c--;
if (is_delim(*c)) /* if NULL (start of string) or pipe: break */
break;
if (!is_special(*c)) {
c++; /* Copy word of regular chars into previous u */
u--; /* previous u */
int count = 0;
while (!is_special(*--c)) /* find the beginnig of words */
count++;
c++;
*u = strndup(c, count);
}
if (is_redir(*c)) { /* If < or > */
if (*c == '<')
redir_stdin = *u;
else
redir_stdout = *u;
if ((u - v) != 98)
u++;
}
}
```
* 此段程式碼的目的為將輸入命令以特殊功能字元做切割,切割成一個個字串以供往後命令的判讀與執行
* 故每當發現非特殊功能字元時便開始計數,紀錄該字串長度並在後續複製該長度的內容到指定的變數空間中
---
## [測驗二](https://hackmd.io/@sysprog/HJsyxSFSd)
1. 功能說明:
* `greeter_routine`:處理使用者的連線請求,進行一些初始設定
* `worker_routine`:接收 HTTP 連線資訊並進行設定,最後將對應的 html 檔案傳回給使用者