I have some service listen.service
which makes the machine act as a TCP server which other clients can connect to. The problem is once the service starts up, it doesn't actually do anything for about 5 minutes because the port was previously used. If I just run the program from command line I could kill the process ID, however I don't have one/can't find one. I am assuming services do not have a PID I can kill. I was using netstat -ap | grep :<portNumber>
to locate the open port used by service but no usable PID was given.
So to clarify my service is some program file which sets an IP and Port as a socket and act as a listening server. If I reboot the machine the service restarts, however nothing happens because the socket/port is still open somehow. After about 5 minutes it starts working as expected. Is there a way I can shutdown that socket/port on boot?
netstat -nap
, or betternetstat -lnpt
or-lnpu
to search for listening tcp or udp service, respectively, then you'll be able to grep by port number.netstat -lnpt
command displays the socket in LISTEN state, but for the PID/Program name its just-
sudo
or as root.