-2

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?

3 Answers 3

3

You can run

ps -o lstart PID

Which will give the start time of the process.

2
  • Thank you Matthew. However, there is a syntax error in your answer. There should be a comma between lstart and PID. Nov 5, 2014 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 Nov 5, 2014 at 7:55
0

I suggest wrapping the php script inside a shell script:

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

0

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

2
  • 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. Nov 4, 2014 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 Nov 4, 2014 at 8:39

You must log in to answer this question.

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