How can I check from Ruby whether a process with a certain pid is running?

前端 未结 9 1917
眼角桃花
眼角桃花 2021-01-30 16:18

If there is more than one way, please list them. I only know of one, but I\'m wondering if there is a cleaner, in-Ruby way.

9条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 17:04

    Under Linux you can obtain a lot of attributes of running programm using proc filesystem:

    File.read("/proc/#{pid}/cmdline")
    File.read("/proc/#{pid}/comm")
    

提交回复
热议问题