linux - 使用 rexec 时的随机错误

标签 linux unix network-programming

我在使用 rexec 时遇到了一个非常奇怪的错误。代码很简单,我只是在循环中调用 rexec:

#include <stdio.h>
#include <errno.h>
#include <netdb.h>
int main() {
  char buffData[1024];
  int i;
  ssize_t j;
  char * l_ahost = "cwp01";
  struct servent * l_servInfo = getservbyname("exec", "tcp");
  for (i = 0; i < 2000; i++) {
    int err = rexec(&l_ahost, l_servInfo->s_port, NULL, NULL, "echo -n .", NULL);
    if (err <= 0) {
      perror("Rexec error");
    } else {
      if (read(err, buffData, 1024) > 0) printf ("'%c' %d\n", *buffData, i);
      close(err);
    }
  }
  return 0;
}

输出是:

muftak : > gcc tst_rexec.c ; ./a.out
    '.' 0
    '.' 1
    '.' 2
    '.' 3
    '.' 4
    ...
    '.' 47
    '.' 48
    '.' 49
    cwp01.eurocontrol.fr: Connection reset by peer
    Rexec error: Illegal seek
    '.' 51
    '.' 52
    '.' 53
    '.' 54
    ...

为什么 rexec 几乎总是正确工作,但并非总是如此?对于这样一个简单的案例,非确定性行为让我很不安。我不知道在哪里搜索对此的解释(当然,stackoverflow 除外)。

我正在使用 Red Hat Enterprise Linux Server 5.8 (Tikanga)

最佳答案

我对 TCP 了解不多,对 rexec 了解更少。你试过命令版本了吗?您的代码建议您可以使用 rexec (1) 而不是 rexec (3)。

祝你好运。

关于linux - 使用 rexec 时的随机错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17151362/

相关文章:

linux - 与 echo 一起使用时脚本不会执行 -

linux - UPNP:绑定(bind)多播

linux - 如何使用两个接口(interface)连接到同一网络和同一子网

linux - 从源代码编译 LAMP - apache2 错误 "no MPM package installed"

c - unix select() 调用 : how to combine fd_sets?

c - 如何在 C 中取消引用 NULL 指针不会使程序崩溃?

python - 重组程序以使用 asyncio

arrays - 在 Golang 中检查 IP 地址 slice 中的 IP 的有效方法

linux - 如何在 Linux/OS X 上温和地杀死 Firefox 进程

带有 strncmp 的 Linux 上的 C 段错误