Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
llseek调用zcat all.tgz |/cycletee时返回ESPIPE_C_Linux_Bash_Pipe_Zcat - Fatal编程技术网

llseek调用zcat all.tgz |/cycletee时返回ESPIPE

llseek调用zcat all.tgz |/cycletee时返回ESPIPE,c,linux,bash,pipe,zcat,C,Linux,Bash,Pipe,Zcat,我将GNUtee修改为cycletee(您可以从下载二进制文件) 它的作用可以通过以下示例来解释: seq 10 | cycletee 1.txt 2.txt 3.txt cat 1.txt // prints 1, 4, 7, 10 cat 2.txt // prints 2, 5, 8 cat 3.txt // prints 3, 6, 9 然后是一个all.tgz(有关构建脚本,请参见附录) all.tgz有三个文本文件,共9000000行 一切都很好。比如: seq 10000000

我将GNU
tee
修改为
cycletee
(您可以从下载二进制文件)

它的作用可以通过以下示例来解释:

seq 10 | cycletee 1.txt 2.txt 3.txt
cat 1.txt // prints 1, 4, 7, 10
cat 2.txt // prints 2, 5, 8
cat 3.txt // prints 3, 6, 9

然后是一个
all.tgz
(有关构建脚本,请参见附录

all.tgz
有三个文本文件,共9000000行

一切都很好。比如:

seq 10000000 | ./cycletee 1.txt 2.txt 3.txt

zcat all.tgz | tee 1.txt > /dev/null

zcat all.tgz | tail // got 9000000 at the last line
除电话外:

zcat all.tgz | ./cycletee 1.txt 2.txt 3.txt
当它读取300万行时,它退出。

strace it我收到这条消息,它退出:

_llseek(2, 0, 0xffbec3d0, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
问题

  • 有人能指出我源代码的问题吗

  • 任何解决问题的调试技术都将受到赞赏。我不知道在这种情况下如何使用
    gdb

附录

  • all.tgz
    可以通过这个Python sciprt构建

  • 环境:Ubuntu 10.04 32位,CentOS 5.4 64位


不能在管道或插座上调用
llseek
ftell
,它们是不可查找的文件

您可以使用像
gdb
这样的调试器(使用它确实值得学习;而且gdb非常好),例如在
\u llseek

您也可以从以下来源使用
strace
ltrace

read:
    buffer[0] = '\0';
    ptr = fgets(buffer, (int) sizeof buffer, stdin);
    if(NULL == ptr) {
        if(ferror(stdin)) {
            error (0, errno, "%s", _("standard input"));
            ok = false;
        }
        flag_break = true;
        break;
    }
    bytes_read = strlen(buffer);


      if (bytes_read < 0 && errno == EINTR)
      {
          flag_continue = true;
          backup_i = i;
          break;
      }
      if (bytes_read <= 0) {
          flag_break = true;
          break;
      }

    if (descriptors[0]
            && fwrite(buffer, bytes_read, 1, descriptors[0]) != 1)
            {
                error (0, errno, "%s", files[0]);
                descriptors[0] = NULL;
                ok = false;
            }
 ...
阅读:
缓冲区[0]='\0';
ptr=fgets(缓冲区,(int)缓冲区大小,标准输入);
if(NULL==ptr){
if(铁合金(标准){
错误(0,错误号,“%s”,“标准输入”);
ok=假;
}
flag_break=true;
打破
}
字节读取=strlen(缓冲区);
if(字节读取<0&&errno==EINTR)
{
flag_continue=true;
备份i=i;
打破
}

如果(bytes_read)你是对的。
zcat在跳转到下一个文件时确实输出了一些二进制数据。我使用
fgets
+
memchr
来确定已读取的字节。它运行良好