slimerjs icon indicating copy to clipboard operation
slimerjs copied to clipboard

Bash script should kill firefox subprocess when killed (trap SIGTERM)

Open tbroyer opened this issue 7 years ago • 2 comments

versions

  • SlimerJS: 0.10.2 (with modified application.ini to whitelist Firefox 51.0)
  • Firefox: 51.0.1
  • Operating system: Ubuntu 16.10

Steps to reproduce the issue

  1. Run some script through SlimerJS that's long enough so you have time to do the following steps in parallel; something like the following should do it:
    setTimeout(function() {
      require('system').stdout.write("Finished after 10 seconds.");
      phantom.exit(0);
    }, 10000);
    
  2. Kill the SlimerJS process (bash script). If the SlimerJS process was run in the background in the same terminal, use kill $!, otherwise killall slimerjs should do it.
  3. Look for running processes: ps aux |grep slimer

Actual results:

The Firefox child process has been orphaned. It is listed by ps and will print its output to the console upon termination.

Expected results:

The Firefox child process is killed.

tbroyer avatar Feb 22 '17 10:02 tbroyer

Is there any update to this? I have lots of FireFox child processes running in the background and not killed because of this issue. Any fix suggestions would be great

jaekunchoi avatar Dec 03 '19 13:12 jaekunchoi

I start slimerjs from python script and i met the same problem. I found interesting solution at https://stackoverflow.com/questions/39420683/killing-a-sub-subprocess-from-python-bash-without-leaving-orphans

# python3

import os
import signal


# start process
process = subprocess.Popen(slimer_command ..., preexec_fn=os.setpgrp)
pid = process.pid

# kill process
os.killpg(os.getpgid(pid), signal.SIGTERM)

Description of os functions: https://docs.python.org/3/library/os.html. I am sure there is enough info to implement the same in bash script.

The idea is that you perform setpgrp before starting slimerjs and then kill its process group.

survtur avatar Jan 05 '21 19:01 survtur