首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

unix环境上测试 是否是流设备

2012-08-29 
unix环境下测试 是否是流设备我在虚拟机上使用ubuntu操作系统,用下面的代码测试/dev/tty ,发现不是 流设备

unix环境下测试 是否是流设备
我在虚拟机上使用ubuntu操作系统,用下面的代码测试/dev/tty ,发现不是 流设备 ,最近在看unix环境下高级编程,上面的怎么测得 /dev/tty 是流设备。。

C/C++ code
#include <stdio.h>; #include <stdlib.h>;  int main(int argc, char *argv[]) {     int fds;    int i;    if((fds = open("/dev/tty","r")) < 0)            printf("open error\n");    if(isastream(fds) == 1)              printf("this dev is a stream dev\n");            else            printf("no\n");    return 0; }


[解决办法]
楼主的代码不对吧, open的第二个参数是int型
if((fds = open("/dev/tty",O_RDONLY)) < 0)


另外我机子上测的也是打印 no


[解决办法]
首先O_RDONLY的确是在头文件中定义的常量,但是它是00,不是"r",所以LZ的参数是错误的,细节很重要,"r"是fopen需要的参数。

其次
C/C++ code
UNIMPLEMENTED(2)           Linux Programmer’s Manual          UNIMPLEMENTED(2)NAME       afs_syscall,  break,  fattach,  fdetach, ftime, getmsg, getpmsg, gtty, isastream, lock, mpx, multiplexer,       prof, profil, putmsg, putpmsg, security, stty, ulimit, vserver - unimplemented system callsSYNOPSIS       Unimplemented system calls.DESCRIPTION       These system calls are not implemented in the Linux 2.4 kernel.RETURN VALUE       These system calls always return -1 and set errno to ENOSYS.NOTES       Note that ftime(3), profil(3) and ulimit(3) are implemented as library functions.       Some system calls, like alloc_hugepages(2), free_hugepages(2), ioperm(2), iopl(2), and vm86(2) only exist       on certain architectures.       Some  system  calls,  like ipc(2), create_module(2), init_module(2), and delete_module(2) only exist when       the Linux kernel was built with support for them.SEE ALSO       obsolete(2)Linux 2.4                         2003-02-28                  UNIMPLEMENTED(2) 

热点排行