ChinaUnix.net
相关文章推荐:

read系统调用

ssize_t ret; while (len != 0 && (ret = read (fd, buf, len)) != 0) { if (ret == -1) { if (errno == EINTR) continue; perror ("read"); break; } len -= ret; buf += ret; } 谁知道下面这段代码怎么解释,特别是那个break if (errno == EINTR) continue; perror ("rea...

by scudong - C/C++ - 2008-11-10 23:31:43 阅读(3923) 回复(15)

相关讨论

测试代码如下 [code] #include #include int main(void) { char buf[40]; int fd; int i; ssize_t nread; if ((fd = open("test.txt", O_RDONLY)) == -1) { printf("open error"); exit(0); } if ((nread = read(fd, (void *)buf, 11)) != 11) { printf("nread = %d\n", nread); printf("sorry, read from test.txt error\n"); } else { for(i = 0; i < 11; i++) printf("i =...

by zhuhefang2006 - C/C++ - 2008-12-17 13:45:49 阅读(1436) 回复(1)

本帖是《linux 2.6.11内核文件IO的系统调用实现分析(open,creat)》的续帖,将主要说明read和write两个文件IO的系统调用实现。所用到的主要数据结构在前面一帖中已经详细说明了,如有需要,请参见前一帖。 6. read 函数 6.1. 原型与参数 ssize_t read(unsigned int fd, char * buf, size_t count) read函数是从打开的文件中读取数据。如read成功,则返回读到的字节数。如已到达文件的尾端,则返回0。如果失败,则返回-1。有多...

by xuediao - 内核/嵌入技术 - 2005-05-23 09:42:24 阅读(7119) 回复(9)

int n = read(fd, buf, len), 当fd为一socket descriptor时,read在哪几种情况下会返回?

by TomTang - C/C++ - 2006-08-21 23:09:11 阅读(905) 回复(2)

#!/bin/sh sleep 3 echo "input a:" read a if [ "$a" == y ]; then echo $a else echo no fi 问题: 如果在shell sleep 的过程敲很多次回车 例如3次 现象为 [root@localhost]#./filename input a: no [root@localhost]# [root@localhost]# [root@localhost]# _ 也就是说shell记住了你敲的这3次回车 怎么能达到这种效果: 不管敲几次回车 只捕捉input a: 出现后的那一次输入 [root@localhost]#./filename i...

by lovec - Shell - 2006-05-17 17:24:49 阅读(1887) 回复(12)

请问“read"在shell scripts上是不是表示从标准输入上读出字符?

by x518889 - Linux论坛 - 2004-04-16 13:48:15 阅读(588) 回复(1)

嵌入式Linux平台下的GPS数据采集涉及到Linux串口编程技术,从串口读取GPS信息需要用到read函数, read函数的定义如下: ssize_t read(int filedes, void *buf, size_t nbytes); 我想问两个问题: 1、这里的参数buf是什么类型的?是char型的吗? 2、当从串口接收到信息并保存到buf中时,我想看buf中保存的信息的第一个字符是不是%,请问 可不可以用if(buf[0]=='%')进行判断?

by 望秦淮 - C/C++ - 2009-05-05 17:55:46 阅读(1344) 回复(4)

echo 1 2 3 |while read a b c do i=5 done echo $i $i的值为啥不能被引用了

by Tim-Wang - Shell - 2009-05-05 17:17:33 阅读(4513) 回复(19)

TMLIMIT=4 read -t $TMLIMIT variable echo if [ -z "$variable" ]; then echo "Timed out, variable still unset." else echo "variable=$variable" fi exit 0 红色部分的一行是什么意思,请高手赐教。

by xyx219 - Shell - 2009-02-17 17:24:29 阅读(1237) 回复(5)

我要将一些输出的结果赋给变量,这样操作为什么不能实现呢? vmstat 3 2|sed 1,3d|awk '{printf("%s %s %s\n",$1,$7,$8)}'|while read A B C ...... 如何才能实现将结果赋给ABC呢? 谢谢~!

by leo_pro - Shell - 2007-06-25 14:45:20 阅读(1355) 回复(9)

环境:SUN-U250 + Solaris8 硬盘:c0t0d0(root),c8t0d0,c9t0d0,c10t0d0,c11t0d0,c12t0d0 目的:练习用disksuite做RAID0,RAID1,RAID5,hotspare... 熟悉常用命令 过程: 1,分区 format-选盘-partition-print-modify 分20MB于7分区,用于放状态数据库副本,其余给分区6 #prtvtoc /dev/rdsk/c0t8d0s2 | fmthard s - dev/rdsk/c9t0d0s2 c10t0d0s2 c11t0d0s2 c12t0d0s2 2,建database #metadb -a -c 2 -f c8t0d0s7 c9t...

by hbjxzl - Solaris文档中心 - 2006-04-01 15:03:20 阅读(705) 回复(0)