1

I know that I can check a process's uptime with the following:

ps -o etime= -p "PID"

where PID = pid number.

I would like to write to a log when this process ends, and include it's uptime. The exact time it exits would be nice, but not strictly necessary. I have a script which automatically restarts it, but I am looking to increase it's stability. In this case, the process is ffmpeg. I am running a very low bandwidth stream from an unstable source, and the process frequently, intermittently fails.

I feel that if I could log it for a day or two, I could try different configurations to see if I can extend the uptime to an acceptable limit.

Thank you for your valuable insight!

  • Add -benchmark to the ffmpeg cmd. Upon exit, ffmpeg will print, among other things, rtime. – Gyan Oct 6 '18 at 15:18
0
ps -eo pid,comm,lstart,etime,time,args

This command lists all processes with several different time-related columns. pipe it to grep ffmpeg to find out about the your process of interest.

The output of the previous command has the following columns:

PID COMMAND                          STARTED     ELAPSED     TIME COMMAND

according to ps man

PID = Process ID
first COMMAND = only the command name without options and without arguments
STARTED = the absolute time the process was started
ELAPSED = elapsed time since the process was started (wall clock time), format [[dd-]hh:]mm:ss TIME = cumulative CPU time, "[dd-]hh:mm:ss" format
second COMMAND = again the command, this time with all its provided options and arguments
  • 1
    Thank you for your answer. I ended up creating a log file and appending to it within my restart script. The script time stamps the restart event. I can now calculate uptime by subtracting the difference between restart events. I run the restart script every minute with crontab. (The script only executes a restart and writes to the log if ffmpeg is not running.) – Jason Oct 9 '18 at 14:42

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.