On Wed, Oct 29, 2014 at 02:09:53PM +0000, Sami Kerola wrote: > Would it make sense to add to 'time' builtin a way to measure how long > a file descriptor is been kept open?
Doesn't really make much sense. If you want multiple independent timers, there's no reason to tie them to open file descriptors. If anything, just make an array of timers, with some shell builtin to start and stop each one. Read the array element to get the elapsed time. I can't say I've ever had a need for this. > This idea came to my mind while writing a script that runs multiple > commands, and I simply wanted to know how long they are busy. I am > aware alternatives exist, but they can get a bit tricky if one wants to > have multiple measurements going on simultaneously. Without any shell modifications, if your operating system provides %s in strftime() then you can get the current time with second resolution (and without forking date) by doing: printf -v somevariable '%(%s)T' -1 It's not much additional effort to keep separate variables (possibly array elements) for each independent timer you want to track. Issue the same printf command again to get the end time, and subtract. If you need millisecond (or even smaller) resolution, or if you need it to work on non-Linux/BSD systems, then I'm afraid Bash is just not the right language for your project.