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.

[10] pry(main)> system('firefox')
=> true
[11] pry(main)> $?.pid
=> 2250
[12] pry(main)> system('kill 2250')
kill: No such process
=> false
[13] pry(main)>

Alternatively if I use popen, i get the right pid
[1] pry(main)> pipe = IO.popen('firefox')
=> #<IO:fd 5>
[2] pry(main)> pipe.pid
=> 2300
[3] pry(main)> (`ps ax | greo firefox`)
sh: 1: greo: not found
=> ""
[4] 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"
[5] pry(main)>


Why am I seeing this difference using system vs popen? Also, any suggestions on best practice is appreciated.

Thanks