2

What I want is,

-bash-3.2$ ps -aef | grep 29137
jeeadm    9794  1190  0 09:22 pts/2    00:00:00 grep 29137
jeeadm   29137     1  0 Sep02 ?        00:00:21 Java

Second Row, Fifth Column entry, as in the output it's just showing the date, Anyway to get the full time-stamp?

3
  • 1
    Does /proc/29137 exist on your system? stat a file in there to get the exact time. Commented Sep 4, 2014 at 11:40
  • 2
    @glennjackman actually that doesn't work. The /proc/<PID> time will be the timestamp the (virtual) directory was created. It gets created the first time something tries to access it (ls, ps, etc).
    – phemmer
    Commented Sep 4, 2014 at 12:51
  • 1
    @Keys this might help you: stackoverflow.com/questions/5731234/… Commented Sep 4, 2014 at 14:06

3 Answers 3

4

You can use the lstart field for this:

# ps -aefO lstart | head       
  PID                  STARTED S TTY          TIME COMMAND
31379 Sat Aug  2 21:31:11 2014 S pts/3    00:00:00 zsh
31399 Sat Aug  2 21:31:11 2014 S pts/3    00:00:00  \_ vim
27313 Sat Aug 30 13:19:27 2014 S pts/4    00:00:20 zsh
27193 Sat Aug 30 13:18:11 2014 S pts/2    00:00:19 zsh
25196 Wed Sep  3 22:37:57 2014 S pts/16   00:00:00 zsh
25231 Wed Sep  3 22:38:00 2014 S pts/16   00:00:00  \_ sudo
25241 Wed Sep  3 22:38:04 2014 S pts/16   00:00:02      \_ zsh
24642 Sat Aug 30 12:50:48 2014 S pts/0    00:00:20 zsh
23366 Thu Sep  4 08:47:30 2014 S pts/18   00:00:00 zsh
1
  • what's the appended 0 for, after -aef? Commented Sep 5, 2014 at 5:01
1

try

ps -p 11517 -o stime

after a day (midnight) ps whill show startday, rather than hour,

after a month, you'll get mon and year,

after a year, you'll get starting year.

1

To find out the timestamp when the process started, you have to calc a bit. Use this command:

echo "$(date +%s) - $(ps -o etime --no-headers -p $pid | \
awk -F'[:-]' '{print ($4+($3*60)+($2*60*60)+($1*24*60*60))}')" | bc -l

The value of $pid should be the process id.

Explanation:

  • echo "$(date +%s): print the timestamp of now
  • ps -o etime --no-headers -p $pid: print the elapsed time of the process without headers
  • awk -F'[:-]': set the delimiter of awk to : and - because the time will be printed in the following format: dd-hh:mm:ss
  • '{print ($4+($3*60)+($2*60*60)+($1*24*60*60))}' calculate the values in seconds
  • bc -l: and pipe the output to bc (timestamp_now - elapsed_seconds = timespamp_at_process_start)

For exmaple i tested it with the init process of a system that runs for 42 days. The output was 1406124152, which is the 07 / 23 / 14 @ 2:02:31pm UTC.

1
  • Quite a calculation! Kudos for your efforts :) but then thought of using the lstart option as need it li'l often.. Commented Sep 5, 2014 at 4:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .