arpak
arpak

Reputation: 133

Can one do date math with ps output?

if i run this command

ps aux | grep -ie ff1 | awk '{print $2 , $9 , $(NF-0)}'

i get this result:

7019 12:33 /var/www/html/tv1/video1.m3u8
13374 17:13 /var/www/html/tv1/asdas.m3u8
15001 05:58 /var/www/html/tv1/dfwef.m3u8
15021 05:58 /var/www/html/tv1/werwe.m3u8
15200 11:45 /var/www/html/tv1/2fsdfsf.m3u8

so second word in each line is time when process started so is there a way i can calculate that time with

date +%H:%M   - awk '{print $9}' 

so i can know how much time each proccess it was running


i want a result like this:

02:20 7019 12:33 /var/www/html/tv1/video1.m3u8

(it means proccess 7019 that starts on 12:33 has been running for 2hours and 20 minutes)

Upvotes: 0

Views: 639

Answers (2)

l0b0
l0b0

Reputation: 58788

This should give what you want - elapsed time, PID, and start time:

$ ps -o etime,pid,bsdstart,cmd
    ELAPSED   PID  START CMD
      00:05 25980  18:33 bash
      00:00 26019  18:33 ps -o etime,pid,bsdstart,cmd

(and I second @CharlesDuffy's sentiment that you definitely should not try to parse this output.)

Upvotes: 0

Kaushik Nayak
Kaushik Nayak

Reputation: 31648

You can use the following commands. first one gives for the specific PID, 2nd for all processes.

ps -o etime= -p <PID>

ps -eo pid,etime

Upvotes: 1

Related Questions