October 21st, 2012, 03:57 PM
Starting and killing processes in ruby
I am missing something here. Here I am launching firefox and then attempting to kill the process. I am confused as to why $?.pid is giving me 2250.
 pry(main)> system('firefox')
 pry(main)> $?.pid
 pry(main)> system('kill 2250')
kill: No such process
Alternatively if I use popen, i get the right pid
 pry(main)> pipe = IO.popen('firefox')
=> #<IO:fd 5>
 pry(main)> pipe.pid
 pry(main)> (`ps ax | greo firefox`)
sh: 1: greo: not found
 pry(main)> (`ps ax | grep firefox`)
=> " 2300 pts/1 Sl+ 0:05 /usr/lib/firefox/firefox\n 2344 pts/1 S+ 0:00 sh -c ps ax | grep firefox\n 2347 pts/1 S+ 0:00 grep firefox\n"
Why am I seeing this difference using system vs popen? Also, any suggestions on best practice is appreciated.