yes, too old and yet too hard stuff. I tried with the above proposed "stat" method but what if I had "touch"-ed the PID proc dir yesterday? This means my year-old process is shown with yesterday's time stamp. Nah, not what I need :(
In the newer ones, it's simple:
ps -o etimes -p <PID>
ELAPSED
339521
as simple as that. Time is present in seconds. Do whatever you need it for.
With some older boxes, situation is harder, since there's no etimes. One could rely on:
ps -o etime -p <PID>
ELAPSED
76-03:26:15
which look a "a bit" weird since it's in dd-hh:mm:ss format. Not suitable for further calculation. I would have preferred it in seconds, hence I used this one:
ps -o etime -p <PID> --no-headers | awk -F '(:)|(-)' 'BEGIN{a[4]=1;a[3]=60;a[2]=3600;a[1]=86400;s=0};{for (i=NF;i>=1;i--) s=s+a[i]*$i}END{print s}'
339544