These are possible output formats for ps h -eo etime
ps h -eo etime
21-18:26:30 15:28:37 48:14 00:01
How to parse them into se
Ruby version:
def psETime2Seconds(etime) running_secs = 0 if etime.match(/^(([\d]+)-)?(([\d]+):)?([\d]+):([\d]+)$/) running_secs += $2.to_i * 86400 # days running_secs += $4.to_i * 3600 # hours running_secs += $5.to_i * 60 # minutes running_secs += $6.to_i # seconds end return running_secs end