How long a process has been running on linux server

If you want to see how long a process has been running on linux, all you have to do is find on its PID and use the following command:

@ ps -o etime= -p "530"
9-18:53:38

but if you want the result in seconds, not in D-H:M:S / timestamp format, use the command like this:

@ ps -o etimes= -p "530"
845608

You can find out the PID of a process using the top command and the process name. i.e php-fpm :

@ top | grep php-fpm

The above command runs until it is forcibly stopped, but if you want to limit to only one time, use the following sintax:

@ top -b -n 1 | grep php-fpm
2245 matrix 20 0 480692 135004 62652 S 0.0 2.2 0:01.38 php-fpm7.4
2246 matrix 20 0 480316 133840 61884 S 0.0 2.2 0:01.17 php-fpm7.4
2247 matrix 20 0 469616 122308 61820 S 0.0 2.0 0:00.54 php-fpm7.4
2262 matrix 20 0 459388 89512 38352 S 0.0 1.5 0:00.37 php-fpm7.4
2263 matrix 20 0 459256 89356 38284 S 0.0 1.5 0:00.09 php-fpm7.4
2307 root 20 0 455356 81092 35408 S 0.0 1.3 0:01.34 php-fpm7.4
Tags: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *