首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >socat fork使netcat挂起

socat fork使netcat挂起
EN

Stack Overflow用户
提问于 2021-03-28 23:11:54
回答 1查看 306关注 0票数 0

我在socat中观察到了一种我以前从未见过的行为。

我在终端中使用以下命令运行socat (在Debian10下)

代码语言:javascript
复制
# socat tcp-listen:8888,reuseaddr,fork exec:"whoami"

并使用netcat连接到8888/tcp:

代码语言:javascript
复制
$ nc localhost 8888
root


Ncat: Broken pipe.

在连接到服务时,我正确地接收到了whoami的输出,但是除非我输入两次新行,否则netcat挂起。

这是预期的行为吗?相反,我希望netcat退出并返回提示符。

socat命令中添加-d -d -d将显示以下几行:

代码语言:javascript
复制
(...)
socat[15813] N execvp'ing "whoami"
socat[15812] N childdied(): handling signal 17
socat[15812] I exec'd process 15813 on socket 1 terminated
socat[15795] I childdied(signum=17)
socat[15812] I waitpid(): child 15813 exited with status 0
socat[15812] I childdied() finished
socat[15812] I transferred 7 bytes from 5 to 6
socat[15795] I waitpid(-1, {}, WNOHANG): No child processes
socat[15812] N socket 2 (fd 5) is at EOF
socat[15812] I shutdown(6, 1)
socat[15812] I terminated child did not leave data for us
socat[15812] I poll timed out (no data within 0.500000 seconds)
socat[15812] I shutdown(6, 2)
socat[15812] I shutdown(5, 2)
socat[15812] N exiting with status 0
socat[15795] N childdied(): handling signal 17
socat[15795] I childdied(signum=17)
socat[15795] I childdied(17): cannot identify child 15812
socat[15795] I waitpid(): child 15812 exited with status 0
socat[15795] I waitpid(-1, {}, WNOHANG): No child processes
socat[15795] I childdied() finished
代码语言:javascript
复制
$ socat -V
socat by Gerhard Rieger and contributors - see www.dest-unreach.org
socat version 1.7.3.2 on Nov 19 2017 13:56:10
   running on Linux version #1 SMP Debian 5.8.10-1~bpo10+1 (2020-09-26), release 5.8.0-0.bpo.2-amd64, machine x86_64
features:
  #define WITH_STDIO 1
  #define WITH_FDNUM 1
  #define WITH_FILE 1
  #define WITH_CREAT 1
  #define WITH_GOPEN 1
  #define WITH_TERMIOS 1
  #define WITH_PIPE 1
  #define WITH_UNIX 1
  #define WITH_ABSTRACT_UNIXSOCKET 1
  #define WITH_IP4 1
  #define WITH_IP6 1
  #define WITH_RAWIP 1
  #define WITH_GENERICSOCKET 1
  #define WITH_INTERFACE 1
  #define WITH_TCP 1
  #define WITH_UDP 1
  #define WITH_SCTP 1
  #define WITH_LISTEN 1
  #define WITH_SOCKS4 1
  #define WITH_SOCKS4A 1
  #define WITH_PROXY 1
  #define WITH_SYSTEM 1
  #define WITH_EXEC 1
  #undef WITH_READLINE
  #define WITH_TUN 1
  #define WITH_PTY 1
  #define WITH_OPENSSL 1
  #undef WITH_FIPS
  #define WITH_LIBWRAP 1
  #define WITH_SYCLS 1
  #define WITH_FILAN 1
  #define WITH_RETRY 1
  #define WITH_MSGLEVEL 0 /*debug*/
EN

回答 1

Stack Overflow用户

发布于 2021-04-04 23:31:55

我用socat观察到了一种我以前从未见过的行为。

观察nc的正常行为,即输出接收到的数据并发送输入数据;如果不希望nc从标准输入中读取数据,可以使用-d选项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66842912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档