lisa icon indicating copy to clipboard operation
lisa copied to clipboard

Method for signals other than SIGKILL

Open mcgov opened this issue 4 years ago • 5 comments

Some programs like to be killed with SIGINT rather than SIGKILL, it would be nice to be able to send signals other than kill for some async programs.

mcgov avatar Aug 20 '21 19:08 mcgov

@mcgov Thank you for suggestions. LISA use below logic to send kill signal. Can you explain more on the suggestions?

There are several things to be considered. The built-in signal constants depends installed Python package. So the signal.SIGTERM here, may be not what want to run remotely. For example, the local is Windows, the remote is Linux. We cannot send SIGTERM to remote. We have to send the hard coded number "9" to remote.

    def kill(self) -> None:
        if self._process:
            if self._shell.is_remote:
                # Support remote Posix so far
                self._process.send_signal(9)
            else:
                # local process should use the compiled value
                # the value is different between windows and posix
                self._process.send_signal(signal.SIGTERM)

squirrelsc avatar Aug 20 '21 19:08 squirrelsc

The specific instance I ran into was a program where you want to kill it by sending INT instead of KILL. KILL just kills it, INT prints some nice statistics and then kills it. I don't think we need to necessarily use the python signal. definition of the signal number, but having a table of signals for each OS that has different definitions doesn't seem too difficult to manage. My general idea was just that the user should be able to specify INT or KILL or whichever signal somehow and be able to send it to a remote process.

mcgov avatar Aug 23 '21 16:08 mcgov

The INT may not be handled correctly by the target process, so the kill may not be effective. The KILL makes sure the process is ended immediately. Another idea is to implement a tool call kill, it can specify which signal to send, and fit to more scenarios. For kill, a graceful way is to send INT firstly, if it's timeout in one or two seconds, then send KILL. Would you like to create the Kill tool?

squirrelsc avatar Aug 23 '21 17:08 squirrelsc

That's true, wrapping kill or killall in a tool would fit the use case

mcgov avatar Aug 23 '21 18:08 mcgov

I can create those :)

mcgov avatar Aug 23 '21 18:08 mcgov

this was implemented in the kill tool, closing

mcgov avatar Dec 01 '23 18:12 mcgov