Know how long a process has been running on Linux

Tux Linux with glitter

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 its PID to use the kill command and kill the process, etc. But there will be times when we must also know how long a process has been running. For example, if it is a strange process, know how long it has been active. Since it could be some type of malware or that it has been started in the background in our system to carry out certain unwanted activity.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 etimes.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

bool (true)