-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?

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47

3 Answers3

3

You can run

ps -o lstart PID

Which will give the start time of the process.

Matthew Ife
  • 23,357
  • 3
  • 55
  • 72
  • 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 05 '14 at 06: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 05 '14 at 07:55
0

I suggest wrapping the php script inside a shell script:

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

Deer Hunter
  • 1,070
  • 7
  • 17
  • 25
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

Hrvoje Špoljar
  • 5,245
  • 26
  • 42
  • 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 04 '14 at 05: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 04 '14 at 08:39