I'm trying to figure out when a command I entered stopped executing, for example
sudo apt-get update
I want information like:
started execution at : 12:00
finished execution at : 12:15
I'm trying to figure out when a command I entered stopped executing, for example
sudo apt-get update
I want information like:
started execution at : 12:00
finished execution at : 12:15
Key point that should be understood about processes is that their metadata is not logged by default. You can, however, obtain certain information while process runs.
As has been stated in related StackOverflow question in wlk's answer, start time can be obtained via -o
flag to ps
and ltime
format specifier:
ps -eo pid,lstart,cmd
Stop time, however, is not tracked by the system usually, so that's something you'll have to track yourself. Knowing PID of a process, you could poll for that PID existence, and echo the timestamp when it disappears
while kill -s 0 $pid ; do : ; sleep 0.25 ; done && date
How about writing our own bash script?
#!/bin/bash
start_time=$(date +"%T")
$*
finish_time=$(date +"%T")
echo "started execution at : $start_time"
echo "finished execution at : $finish_time"
Save the script as logscript.sh
Make it executable by using chmod +x logscript.sh
You can run 'command' using ./logscript.sh command
For example, ./logscript.sh sudo apt-get update
Check this site for interesting time-display formats.
time
before any command tells the execution time it took (in minutes and seconds). – Kulfy Dec 19 '18 at 10:41acct
package, it is used for process accounting, and logs start- and run-time among other info. – Soren A Dec 19 '18 at 11:54