Search code examples
bashunixtimestampps

how to get current timestamp when using ps in a bash script?


So I am writing a shell script that gets all the current processes running, and pipes them into grep to filter out the ones I need.

But I also need it to give me a timestamp Either when the PS occurs, or when the process was started, it doesnt matter, I just need A time. All the processes just take fractions of seconds.

My command is this:

ps -U USERNAME -o rss=MEM,comm=CMD,pid=PID

I tried going like this:

ps -U USERNAME -o rss=MEM,comm=CMD,pid=PID, start=START

but that just gives me a time like hh:mm:ss. I need something more precise than this. Timestamps are ideal.

Any ideas?


Solution

  • does the following satisfy your need?

    date; ps -U USERNAME -o rss=MEM,comm=CMD,pid=PID