Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8717263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:15:53+00:00 2026-06-13T06:15:53+00:00

Is there a ruby method to get process start time? Something like the following

  • 0

Is there a ruby method to get process start time? Something like the following in shell:

 $ ps -p $$ -o lstart
 STARTED
 Thu Oct 18 11:49:22 2012

I was hoping to avoid parsing ps output. Also, I know how to parse /proc/self/status on linux to get at the info, but I was hoping for a more portable solution.

Update:
A portable way to do this is exactly what I wanted. I used sys/proctable and use the following line to get what I wanted:

ProcTable.ps($$).starttime

Thanks, Koen.

Update:
I was playing around a bit with this and found that it’s not as portable as I thought. On Darwin, a Time object is returned. On Linux, an integer is returned that corresponds to the number of jiffies since boot. Unfortunately, you need to use the sysconf syscall to get the number of ms/jiffy. This syscall is not available directly on ruby. I used the following to get the proc start time on Linux:

module LinuxCLib
  extend FFI::Library
  ffi_lib 'c'

  @@cg = FFI::ConstGenerator.new(nil, :required => true) do |gen|
    gen.include('unistd.h')
    gen.const(:_SC_CLK_TCK)
  end

  attach_function :sysconf, [:int], :long

  def self.hz
    self.sysconf(@@cg["_SC_CLK_TCK"].to_i)
  end
end

def self.get_proc_starttime
  proc_jiffies_since_boot_starttime = Sys::ProcTable.ps($$).starttime
  stat_lines = File.open("/proc/stat").readlines
  system_s_since_epoch_boottime = catch(:boottime) do
    stat_lines.each do |line|
      split_line = line.split
      throw :boottime, split_line[1].to_i if split_line[0] == "btime"
    end
    nil
  end
  proc_s_since_epoch_starttime = (
      proc_jiffies_since_boot_starttime/LinuxCLib::hz + system_s_since_epoch_boottime)
  Time.at(proc_s_since_epoch_starttime)
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:15:54+00:00Added an answer on June 13, 2026 at 6:15 am

    There is a gem that could do that: sys-proctable

    It parses the files in /proc

    Install the gem

    gem install sys-proctable
    

    Require the gem

    require 'sys/proctable'
    include Sys
    

    For all processes

    ProcTable.ps{ |p|
        puts p.comm
        puts p.starttime
    }
    

    For just a single process (like in your example)

    p = ProcTable.ps($$)
    puts p.inspect
    

    And if you don’t want to use the gem, maybe you can extract the part of how they parse the /proc files from the source

    EDIT:

    I misread the part that you do know how to parse the /proc files. But maybe the gem still can be of use to you, making it portable and so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a gem or a library to get ruby 1.9 methods like [1,
Is there a way to get a true proc from a method in Ruby?
I find myself wondering if there's a built-in Ruby method to get the nth
Is there a Ruby method I can call to get the list of installed
In Ruby is there any method that lists all the global variables available at
Is there a well-designed method that can run my ruby program from anywhere? I
Is there a pretty way to make a series of method calls in ruby
Is there some method to show Session, ENV, POST, and GET data in a
Is there an equivalent ruby/RoR method for PHP get_meta_tags. I am looking to read
I'm hoping to implement something like all of the great plugins out there for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.