2

I am trying to use socat command to simulate a tcp disconnect between my client service and EMS broker process on a remote host. I am running this socat command

socat TCP-LISTEN:8123,fork TCP:remotehost name:port

I run this command on a server say server1 - and I am configuring my client service to connect to server1:8123 - which enables client to be able to connect to the actual EMS broker.

However - when I want to simulate a disconnection - I am killing the socat process ( i find the pid by ps aux | grep socat ) - but that does not seem to kill the connection - I can see that client is still able to talk to the ems broker. ( why is socat not killed at this stage ? )

However - If I now restart my client then it fails connecting to broker ( because now the socat process is really dead ).

I cant figure out whats happening here - how can I ensure that socat process is definitely killed ?

1 Answer 1

1

I think it depends on how you kill the socat process. Probably socat does not accept the signal you are using, try with 9:

kill -9 pid

The output of ps should show more than one pid for the socat process, you have to choose the right one.

Right after you have executed the socat command you should see just one process:

[root@centos03 ~]# ps aux | grep socat
root     28801  0.0  0.3  41684  1936 pts/0    S+   15:22   0:00 socat TCP-LISTEN:8123,fork TCP:web:80
root     28803  0.0  0.1 103244   848 pts/3    S+   15:22   0:00 grep socat

Once the client has established a connection you shoud see another process:

[root@centos03 ~]# ps aux | grep socat
root     28801  0.0  0.3  41684  1940 pts/0    S+   15:22   0:00 socat TCP-LISTEN:8123,fork TCP:web:80
root     28807  0.0  0.2  45860  1452 pts/0    S+   15:25   0:00 socat TCP-LISTEN:8123,fork TCP:web:80
root     28809  0.0  0.1 103244   844 pts/3    S+   15:26   0:00 grep socat

Now if you kill the process with pid 28801 no new connection will be allowed but the client will be still connenct until you kill the process with pid 28807

2
  • I am already using kill -9 pid. I even tried Cntrl+C
    – Bhaskar
    Dec 19, 2013 at 12:42
  • Maybe you are killing the wrong process, I've edited my answer. Dec 19, 2013 at 14:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .