Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I started a hash check of a large file and don't want to restart it using time. How can I get the wall clock time without using time at the beginning or using date right before I invoke a command?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

For a running process you can do this:

PID=5462
command ps -p "$PID" -o etime
command ps -p "$PID" --no-headers -o etime

As a general feature you can modify your shell prompt. This is my bash prompt definition:

TERM_RED_START=$'\033[1m\033[31m'
TERM_RED_END=$'\033(B\033[m'
PS1='\nec:$(ec=$?; if [ 0 -eq $ec ];
then printf %-3d $ec;
else echo -n "$TERM_RED_START"; printf %-3d $ec; echo "$TERM_RED_END";
fi) \t  \u@\h:\w\nstart cmd:> '
PS2="cont. cmd:> "

The relevant part for you is the \t for the time.

This does not solve all problems, though. The new prompt will show when the process has ended but the former prompt may have been quite old when the command to be measured was started. So either you remember to renew the prompt before starting long running commands or you have to remember the current time when you want to know how long the current process will have taken.

For a complete solution you need an audit feature (which logs the start and end time of processes). But that may cause a huge amount of data if it cannot be restricted to the shell.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.