I am running test for a network program which uses TCP sockets. To verify a bug fix, I need to reproduce a \"Broken pipe\" error at the socket layer, but I don\'t know how. Any
A "Broken pipe" error message generally comes from the shell when it detects that a child it created has exited due to a SIGPIPE signal. So you can may be able to cause one manually by killing a child with a SIGPIPE (kill -PIPE %1
to kill the first background command).
SIGPIPE is generated by the kernel and sent to any process that tries to write to a pipe or socket after the other end has been closed.
'Broken pipe' means that you have written to a connection that has already been closed by the peer. So, have the peer close the connection.
I looked around and couldn't find a procedure documented anywhere, so here you go.
I found a server in my ssh config that uses an 'nc' proxy command.
host server
ProxyCommand /usr/bin/nc -4 -n -X 5 -x 127.0.0.1:55555 %h %p
I ran an ssh with ServerAlive options set to 1:
> ssh -o ServerAliveInterval=1 -o ServerAliveCountMax=1 e3prosup@server
Then in a different session, I found the 'nc' process associated with the ssh and killed it. Both kill -9 (SIGKILL) or kill -13 (SIGPIPE) will work.
> ps -efa
e3prosup 19502 10955 0 11:43 pts/6 00:00:00 ssh -o ServerAliveInterval=1 -o ServerAliveCountMax=1 e3prosup@server
e3prosup 19503 19502 0 11:43 pts/6 00:00:00 /usr/bin/nc -4 -n -X 5 -x 127.0.0.1:55555 server 22
> kill -13 19503
Now the ssh session gets:
e3prosup@server> Write failed: Broken pipe