大家好,我写了一个socket程序,这个程序在执行的时候出现了 bind:bad file descriptor 这个错误,请问是怎么回事呀? 我是这样bind的 应该没有错啊,请大家帮帮忙。
if(write(fd,&data,2)<0) { printf("fd is %dn",fd); printf("i2c: watchdog write error.n"); printf("Error :%sn",strerror(errno)); close(fd); exit(-1); } 咝绣e誤打印信息為 fd is 3 i2c: watchdog write error Error: bad file descriptor 在這段程序之前有ioctl設置,read等 都沒有出錯 到了write錯了,怎麽解決啊?
if(write(fd,&data,2)<0) { printf("fd is %dn",fd); printf("i2c: watchdog write error.n"); printf("Error :%sn",strerror(errno)); close(fd); exit(-1); } 咝绣e誤打印信息為 fd is 3 i2c: watchdog write error Error: bad file descriptor 在這段程序之前有ioctl設置,read等 都沒有出錯 到了write錯了,怎麽解決啊?
[code][xx@xx~/lx] $ls 1.pl test.txt [xx@xx ~/lx] $cat 1.pl #!/usr/bin/perl use warnings; use strict; print "1$!\n"; my $a=readpipe("ls"); print "$a\n"; print "2$!\n"; [xx@xx ~/lx] $./1.pl 1 1.pl test.txt 2bad file descriptor[/code]为什么去readpipe读取以后,$!都会保存bad file descriptor,因为这个错误,往往导致代码异常中断。 谢谢
第一次select的是server的socket,accept一个连接的fd之后加入select,再select就出错了... 在select之前清空fdset,重新把可用的fd 放入fdset,以及select时maxfd+1等问题我都查过了,仍然找不到出错的原因....
当我的perl 脚本中有这些 语句的时候 总是 运行报错: bad file descriptor! 谁能指点一下啊?谢谢了! 错误语句如下:open OUT, "command |" or die "Could not open command: $!\n"; 或者 open(CHILD, "./read-stdout-pipel 2>&1 |") or die "Can't open: $!"; 或者 open($H,"tail -f -n 50 z.txt |") or die $!;
[code] char buf_s[800]; if(events.events & EPOLLIN) {//有读取的数据 cfd = events.data.fd; memset(buf_s, 0, 800); if (read(cfd, buf_s, 800)< 0) { perror("read error"); acceptfz(arg,cfd,0); continue; } }[/code]报 read error: bad file descriptor 这个错误 是他自己通知说有数据可读,结果一读就出这样的错误,怎么回事呢?