I want to run some application in background and later kill it by pid.
pipe = IO.popen(\"firefox \'some_url\' 2>&1 &\")
pipe.pid
Since you are running it in the background (command &
), you get the interpreter's PID:
>> pipe = IO.popen("xcalc &")
>> pipe.pid
=> 11204
$ ps awx | grep "pts/8"
11204 pts/8 Z+ 0:00 [sh]
11205 pts/8 S+ 0:00 xcalc
Drop the &
:
>> pipe = IO.popen("xcalc")
>> pipe.pid
=> 11206
$ ps awx | grep "pts/8"
11206 pts/8 S 0:00 xcalc
For the additional issue with the redirection, see @kares' answer