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