What is the meaning of $$ in Ruby?

前端 未结 5 2019
囚心锁ツ
囚心锁ツ 2021-02-19 08:19
irb(main):002:0> $$
=> 5052

What is the meaning of $$ in Ruby and How/Where to use it?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 08:52

    pipe = IO.popen("")
    if pipe
      STDERR.puts "In parent, child pid is #{pipe.pid}"
    else
      STDERR.puts "In child, pid is #{$$}"
    end
    

    This example shows how the process ID can be used. Process ID is part of 'Execution Environment Variables' (part of predifined variables).

提交回复
热议问题