Linux????е?dup??????
???????????? ???????[ 2013/1/17 9:57:35 ] ????????
????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??????????????????????????????豸????????????????丸????“????”??????????????????????????????????????????????????????????????????????????????е??????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11