slimerjs
slimerjs copied to clipboard
Bash script should kill firefox subprocess when killed (trap SIGTERM)
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
- 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);
- Kill the SlimerJS process (bash script). If the SlimerJS process was run in the background in the same terminal, use
kill $!
, otherwisekillall slimerjs
should do it. - 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.
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
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.