# How to check process running time

**URL:** <https://forum.ansible.com/t/how-to-check-process-running-time/32980>\
**Category:** Ansible Project\
**Created:** [May 20, 2020, 7:29am UTC](https://forum.ansible.com/t/how-to-check-process-running-time/32980 "2020-05-20T07:29:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jenisha\_T](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@Jenisha\_T](https://forum.ansible.com/u/Jenisha_T)\
**Post date:** [May 20, 2020, 7:29am UTC](https://forum.ansible.com/t/how-to-check-process-running-time/32980/1 "2020-05-20T07:29:19Z")

</div>

I need to kill a process if its older than 1 hour. I have process id how to check if its older than 1 hour

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 20, 2020, 7:51am UTC](https://forum.ansible.com/t/how-to-check-process-running-time/32980/2 "2020-05-20T07:51:47Z")

</div>

Hi

How is this related to ansible?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [May 20, 2020, 8:26am UTC](https://forum.ansible.com/t/how-to-check-process-running-time/32980/3 "2020-05-20T08:26:12Z")

</div>

There is no such Ansible module. It'll be necessary to use 'command'. For  
example, in Linux or \*BSD, get elapsed time of the process in seconds

&nbsp;&nbsp;&nbsp;&nbsp;- command: 'ps -o etimes -p {{ my\_pid }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: result  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: result.stdout\_lines

and kill the process if it's older than 1 hour

&nbsp;&nbsp;&nbsp;&nbsp;- command: 'kill {{ my\_pid }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: result.stdout\_lines.1|int \> 3600

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Jenisha\_T](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@Jenisha\_T](https://forum.ansible.com/u/Jenisha_T)\
**Post date:** [May 21, 2020, 11:41pm UTC](https://forum.ansible.com/t/how-to-check-process-running-time/32980/4 "2020-05-21T23:41:11Z")

</div>

It worked . Thankyou
