Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 doesn't matter, I just need a time. All the processes just take fractions of a second.

My command is this:

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

I tried going like

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.

What should I do?

share|improve this question

Since you need more precise time than seconds, you can either generate your own timestamp with:

date +%Y%m%d%H%M%s.%N

keep in mind that date itself takes ~.001s to run (dependent on system), so the nanoseconds may not be the right number of significant digits.

or you can look in /proc/$THIS_PID/stat using stat to see the start time of /init we can use:

stat -c %x /proc/1/stat

%x   Time of last access
%X   Time of last access as seconds since Epoch
%y   Time of last modification
%Y   Time of last modification as seconds since Epoch
%z   Time of last change
%Z   Time of last change as seconds since Epoch

2012-03-10 12:18:45.328784363 +0800

though if the processes are really fast it it may be missing by the time you get to it, this would be the case for other solutions as well, but you may want to check that the file exists first

share|improve this answer

Try using ps -ef this should give the start date and time

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .