Linux – How to stop a infinite running process(ztail) started by a ssh session after that session is closed

linuxlinux-kernellinux-networking

I have a peculiar problem. My server supports multiple ssh session simultaneously, so that multiple admins can manage it simultaneously.

We have a command which calls ztail to show the compressed log files and when the current ssh session is closed (without pressing ctrlc, to stop the tail command), the command should ideally stop working.

But what I observed when I start a new ssh session is that the process ztail is still running in the background and consuming CPU, even though the previous session was closed.

How can I determine when the session is closed, so that I can use that variable/flag to close/stop any commands initiated by that previously closed session?

Best Answer

You don't say what is the command that you run in your ssh session and in turn invokes ztail, nor whether this command keeps running or not.

When you close the session, that command receives a SIGHUP signal, and should then dispose of ztail.