How to check process running time

22 views
Skip to first unread message

Jenisha T

unread,
May 20, 2020, 3:29:19 AM5/20/20
to Ansible Project
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

Dick Visser

unread,
May 20, 2020, 3:52:14 AM5/20/20
to ansible...@googlegroups.com
Hi

How is this related to ansible?
 

On Wed, 20 May 2020 at 09:29, Jenisha T <joy...@gmail.com> wrote:
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6042ef03-2a2c-48ab-b338-55aac3c9bc46%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Vladimir Botka

unread,
May 20, 2020, 4:26:33 AM5/20/20
to Jenisha T, ansible...@googlegroups.com
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

- command: 'ps -o etimes -p {{ my_pid }}'
register: result
- debug:
var: result.stdout_lines

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

- command: 'kill {{ my_pid }}'
when: result.stdout_lines.1|int > 3600

HTH,

-vlado

T. JENISHA

unread,
May 21, 2020, 7:41:47 PM5/21/20
to Vladimir Botka, ansible...@googlegroups.com
It worked . Thankyou
Best Regards
Jenisha T





Reply all
Reply to author
Forward
0 new messages