Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

ps show start time in ISO 8601 format

From unix.stackexchange.com:

ps -e --no-headers -o lstart,pid,command --sort=start_time | awk '{ cmd="date -d\""$1 FS $2 FS $3 FS $4 FS $5"\" +\047%Y-%m-%dT%H:%M:%S\047"; cmd | getline d; close(cmd); $1=$2=$3=$4=$5=""; printf "%s\n",d$0 }'


2021-08-24T07:42:42     25863 [kworker/0:3-events]
2021-08-24T07:42:42     25927 [kworker/2:3-events]
2021-08-24T07:43:08     27437 [kworker/u9:0-xprtiod]
2021-08-24T07:44:00     30436 /usr/lib/firefox/firefox -contentproc -childID 114 -isForBrowser -prefsLen 10798 -prefMapSize 258189 -parentBuildID 20210504152106 -appdir /usr/lib/firefox/browser 5803 true tab
2021-08-24T07:49:28     16224 [kworker/u8:0-kcryptd/254:0]
2021-08-24T07:49:34     16656 sleep 2
2021-08-24T07:49:36     16688 sleep 0.75

You of course can adapt this to whichever additional parameters you need to send to ps, or grep for.

Comments