分类: LINUX
2012-03-12 09:28:00
int main(int argc,char *argv[])
{
int fp1,fp2;
printf("stdin is:\t%d\n",fileno(stdin)); //标准输入设备
printf("stdout is:\t%d\n",fileno(stdout)); //标准输出设备
printf("stderr is:\t%d\n",fileno(stderr)); //标准错误输出设备
if((fp1=open("/etc/xinetd.d/cvs",O_WRONLY))==-1)//打开文件
{
perror("open");
exit(EXIT_FAILURE);
}
if((fp2=open("/etc/xinetd.d/kshell",O_WRONLY))==-1) //打开文件
{
perror("open");
exit(EXIT_FAILURE);
}
printf("cvs file is :\t%d\n",fp1);//打印文件描述符
printf("kshell file is:\t%d\n",fp2); //打印文件描述符
close(fp1);
close(fp2);
return 0;
}
[root@localhost yangzongde]# gcc -o fileno_example fileno_example.c
[root@localhost yangzongde]# ./fileno_example
stdin is: 0
stdout is: 1
stderr is: 2
cvs file is : 3
kshell file is: 4
1.2 、
转自