-1

I'm using codeceptjs with shelljs.

In one of tests I'm invoking a Go application like this:

const shell = require('shelljs')


let execution = shell.exec('./myGoApplication')
execution.kill();

I tried to stop it with kill with different params but it is not working.

Does anyone knows how to stop Go application from running?

EDIT:

This code doesn't stop either

execution.kill('SIGINT');

https://github.com/shelljs/shelljs

Kyryl Zotov
  • 1,788
  • 5
  • 24
  • 44
  • 1
    There's nothing at all special about a Go program. To stop a running executable, you have two options: Have the program exit on its own, or have the OS kill it. There's really no third option. As for getting it to exit on its own (i.e. a graceful shutdown), there are many ways to request this of a running program—they all depend on the program supporting them. A common way is to send a SIGINT signal that the program intercepts and uses as a signal to begin a shutdown. – Jonathan Hall Aug 09 '21 at 09:59
  • @Flimzy for me I use that go program in Automation tests so I want it to be cleaned in the end of test. So that I want to end it from outside. `execution.kill('SIGINT');` Is not working – Kyryl Zotov Aug 09 '21 at 11:06
  • 2
    SIGINT just sends a signal to the program. Unless the program interprets that to mean it should exit, it won't do anything. – Jonathan Hall Aug 09 '21 at 11:07
  • @Flimzy Understood, thanks – Kyryl Zotov Aug 09 '21 at 11:12
  • 1
    this might help https://superuser.com/a/97372/592596 –  Aug 09 '21 at 11:14
  • 1
    See also https://stackoverflow.com/q/58566646/13860 – Jonathan Hall Aug 09 '21 at 11:17

1 Answers1

1

The kill command accepts the termination signal as its first argument.

let execution = shell.exec('./myGoApplication')
execution.kill('SIGINT');

Here is a list of all signals:

https://unix.stackexchange.com/a/317496

Charlie
  • 22,886
  • 11
  • 59
  • 90