How to check process running time

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

Hi

How is this related to ansible?

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

1 Like

It worked . Thankyou