Skip to content

Instantly share code, notes, and snippets.

@andrewp-as-is
Created May 10, 2019 11:47
Show Gist options
  • Save andrewp-as-is/b85e871926a62c2d3a787b9c2d1a89f0 to your computer and use it in GitHub Desktop.
Save andrewp-as-is/b85e871926a62c2d3a787b9c2d1a89f0 to your computer and use it in GitHub Desktop.
pid elapsed time
#!/usr/bin/env bash
ps -eo pid,comm,etime | perl -ane '@t=reverse split(/[:-]/,$F[2]); $s=$t[0]+$t[1]*60+$t[2]*3600+$t[3]*86400; print "$F[0]\t$F[1]\t$F[2]\t$s\n"'
#!/usr/bin/env bash
set -- 1
ps -p $1 -oetime= | tr '-' ':' | awk -F: '{ total=0; m=1; } { for (i=0; i < NF; i++) {total += $(NF-i)*m; m *= i >= 2 ? 24 : 60 }} {print total}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment