????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??????????????????????????????璞�????????????????涓�????“????”??????????????????????????????????????????????????????????????????????????????械??????????