I have a php script (cron job) running on my server which takes up a lot of cpu. I took a look on the code and couldn't find anything wrong. Now I have to check the logs for anomaly and for this I need to get the script start time and/or uptime. I tried top, ps -aux, htop etc but couldn't get that. Is there any other command/method available for this?

ps -aux | grep php shows Oct 11, the date. But How can I get the time?


You can run

ps -o lstart PID

Which will give the start time of the process.

  • Thank you Matthew. However, there is a syntax error in your answer. There should be a comma between lstart and PID. – Sachin Murali G Nov 5 '14 at 6:20
  • No there shouldn't, your supposed to put the pid you want in PID. If you want the start time of EVERY Process then you would do ps -Ao lstart,pid – Matthew Ife Nov 5 '14 at 7:55

I suggest wrapping the php script inside a shell script:

date >/your/log ; /usr/bin/time /path/to/your.php


If you know PID of script; you can get the start time of script with

stat -c %z /proc/PID

Additionally you can analyze what's going on in script with strace e.g.

strace -p PID -s 128 -tT

This will give you idea where time is spent in this process which appears to be trashing your CPU

  • stat -c %z will show the Time of last change right? I need to get the time at which the script started or the script uptime so that I can match it with my log and find the issue. And strace is giving me just a blank output and stat -c %z is giving me the current date. – Sachin Murali G Nov 4 '14 at 5:13
  • that is the time directory of process was created; time is never altered throughout the process lifetime; make sure that you put PID of process instead PID – Hrvoje Špoljar Nov 4 '14 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.