All who already know GNU / Linux or Unix systems will know the ps command that allows us to monitor processes, as well as other programs that allow us to work with open processes in our operating system. Well, we have already published some tutorials to carry out some administrations related to the processes, but today we are going to dedicate this article to create a post in which we will describe step by step and in a simple way how you can know the execution time of a process has been active.
On some occasions we will not only have to know details such as the files opened by the process or your PID to use the kill command and kill the process etc. But there will be times when we must also know the time a process takes to execute. For example, if it is a strange process, know how long it has been active. Since it could be some type of malware or one that has been started in the background on our system to carry out certain unwanted activity. By knowing the time we will know the extent of the damage. And this is just an example, there may be many more cases where we have to know the execution time. Well, for that we will only need the ps command and also pdof. What we will do is use the second to know the PID of the process that we want to check. Obviously, if it were a strange process, there would be no choice but to monitor all active processes and detect it manually ... But in the case of being known software:
pidof httpd
In this case, it will return the PID of the process for the HTTP daemon, but if you want to find out another program, use its name instead of this one. Let's imagine that it returns the PID 8735. Well, the following is to use ps to determine the time with the etime option:
ps -p 8735 -o etime
And it will give us the days, hours, minutes and seconds that it has been running. If you want to display the time in seconds instead of DD-HH: MM: SS format, then use the option times.