Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev AndrewRadev/
Last active Oct 21, 2018

What would you like to do?
Keep track of a long-running process
# Given a long-running process in the terminal:
# - Ctrl+Z to suspend it
# - Run `keep-track`
# - Output resumes, when done will show a notification with the time it took for the process to run
# Can be customized with an `--icon` to `notify-send`,
# maybe a sound effect added in the `&&` list.
function keep-track() {
last_command=$(history | tail -1 | cut -d' ' -f3-)
pid=$(jobs -p | sed 's/.*+\s*\([0-9]\+\) suspended.*/\1/' | head -1)
start_time=$(date --date="$(ps -p $pid -o lstart | tail -1)" +%s)
fg && notify-send "keep-track" "Done: $last_command, Time: $(expr $(date +%s) - $start_time)s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.