andrewslotin/selenium-phantomjs — pull request #2 by nixikanius (2013-12-20 15:57:45+00:00)
Title: No shell instance run

This done to guarantee normal work with pid in Linux (in Mac OS and I think in *BSD no problem with this).

When you use run of program via shell by pass string in Process.spawn in result of this method you will always get incorrect pid in Linux. In this case result pid is always belongs to "sh -c %RUN_STRING%" command. It happens because characteristic of Linux process tree.

For example, when I run in Linux "ruby test.rb" with this sample of code:

phantomjs = Selenium::Phantomjs::Instance.new(pid_filepath)
pid = phantomjs.run({:webdriver => 9134, "ignore-ssl-errors".to_sym => "true", "load-images".to_sym => "false"})

Process tree looks like this:

990 28210 0.0 0.0 3956 580 pts/1 S+ 18:25 0:00 | \_ ruby test.rb
990 28216 0.0 0.0 3956 580 pts/1 S+ 18:25 0:00 | \_ sh -c /usr/local/bin/phantomjs --webdriver="9134" --ignore-ssl-errors="true" --load-images="false"
990 28218 10.0 0.4 1623856 16576 pts/1 Sl+ 18:25 0:00 | \_ /usr/local/bin/phantomjs --webdriver=9134 --ignore-ssl-errors=true --load-images=false

In ruby script as pid I've got 28216 insted of 28218. So when after I call "phantomjs.die!" I see that my phantomjs is still running.

Using directly run of program in Process.spawn solves this problem.