1

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?

3
  • I think netstat shows symbolic service name for the port (from /etc/services), not numeric, but grep searches for the number and obviously fails. Use netstat -nap, or better netstat -lnpt or -lnpu to search for listening tcp or udp service, respectively, then you'll be able to grep by port number. Commented Dec 2, 2022 at 18:47
  • @NikitaKipriyanov the netstat -lnpt command displays the socket in LISTEN state, but for the PID/Program name its just - Commented Dec 2, 2022 at 19:00
  • You had insufficient privileges to see it then. Run it under sudo or as root. Commented Dec 3, 2022 at 11:35

0

You must log in to answer this question.

Browse other questions tagged .