Reputation
Top tag
Next privilege 125 Rep.
Vote down
Badges
3
Newest
 Teacher
Impact
~244 people reached

  • 0 posts edited
  • 0 helpful flags
  • 1 vote cast
Jun
9
revised Get process elapsed time in seconds
Clarify use of `set -vx`
Jun
9
revised Get process elapsed time in seconds
Clarified sections of the command script
Jun
9
comment Get process elapsed time in seconds
@Gilles, I agree. I'll neaten it up when I get back on that system.
Jun
9
comment Get process elapsed time in seconds
The user (or application in my case) can change the system time between the process start and checking of elapsed time. You can try elapsed() { expr $(date +%s) - $(stat -c %Y /proc/${MYPID}/environ ); }; sleep 10 & export MYPID=$!; elapsed; sleep 1; elapsed; sudo date +%F\ %T -s "$(date -d "$(date +%F\ %T) 1 hour ago")"; elapsed. My result is 0, then 1, then -3599. Don't forget to reset your time, optionally like sudo rdate 0.us.pool.ntp.org (it takes a minute or two for me). Wall clock time is a hazardous way to keep track of durations and should be avoided when uptime is usable.
Jun
8
answered Get process elapsed time in seconds
Jun
8
comment Get process elapsed time in seconds
Nope, this fails. The difference was the existence of files in the directory or not. If there are no files, then * remains unsubstituted. Otherwise, it expands and messes up the expr.
Jun
8
awarded  Teacher
Jun
8
awarded  Editor
Jun
8
revised Get process elapsed time in seconds
deleted 23 characters in body
Jun
8
answered Get process elapsed time in seconds
Jun
8
awarded  Supporter
Jun
8
comment Get process elapsed time in seconds
Given that the only comments I've seen about ticks/jiffies are to avoid dealing with them unless you want to carefully maintain your code, I'm going to stay away from that approach (and no, I don't presently have getconf). Your eval did work but I now have it working without as well. :[ I swear I tried anywhere from 0-6 `s before the *` and it didn't work, but it now does with \\*. Apparently I was debugging too many different avenues at once and ended up not having tested what I thought I had. Bugger and sorry.
Jun
8
comment Get process elapsed time in seconds
This system set's it's time on startup from the application. Since this occurs between the process start and the checking of the process elapsed time, it is pretty much guaranteed to be wrong. Such timestamps are generally hazardous even when not guaranteed to be a problem. Thanks for taking the time to respond.
Jun
8
comment Get process elapsed time in seconds
This is being developed in test code where there are two copies of BusyBox. I am explicitly using the testing version for ps because the system version didn't include support for -o. In the second case I was just trying it out to see if there was a difference between the two binaries for expr as well.
Jun
8
asked Get process elapsed time in seconds