????2??????????е??????????


static int init(void * unused)
{
 ...
 if (sys_open((const char __user *) "/dev/console"?? O_RDWR?? 0) < 0)
  printk(KERN_WARNING "Warning: unable to open an initial console. ");
 //?????????????init?????????????????????????ж??????????????????????д?????

 (void) sys_dup(0);//????dup??/dev/console????????????Σ???????????豸????????????????????????(??????????1??2)
 (void) sys_dup(0);
 //????sys_open((const char __user *) "/dev/console"?? O_RDWR?? 0) ?????У?init???????3???????????(?????????????????????)
 ...
}
 


????3?????????

?????????????????????????????

????????????shell??????????????“echo hello!”?????????????shell??????????????????echo???????“hello!”????shell?????????????????bin/echo?????fork()?????????????????bin/echo?????????????????????????????shell??????????????????????????stdin????????????stdout???????????????stderr??????????????????????0??1??2????????echo????????????????????“hello!”д??????????????????????????????????????????????????????“echo hello! > foo”?????????????????????????????foo?С??????????????shell?????????????????????????????0??1??2???????????н?????????????У?

??????1???????????????foo?????foo?????????????????????????????????3??

??????2?????dup()???????stdout???????????1????file?????????????4??????????stdout??file?????????????

??????3?????stdout????1???????????????4???????stdout????и??????????stdout?????δ??????????????1???????λ?á?

??????4?????dup()??????3????????????????foo????????1???????????λ????????3????????????1?????????????????stdout??????????foo??

??????5???????????fork()??exec()?????????????echo????????????echo?????3???4????????????0??1??2???????????????????1????????????stdout??????????foo?????echo????stdout???д??“hello!”????д????foo?С?

??????6?????shell????????foo??1????3???????????dup()??close()??2??????stdout??????shell?????0??1??2???????????/????????

?????????????echo?????????????????е?????????stdout??????stdin??stderr??????????????????????????????豸????????????????丸????“????”??????????????????????????????????????????????????????????????????????????????е??????????