Linux: Kill Process based on Start Time (STIME)

One of the server that I am working with has some infinitely running PHP process. Due to incorrect way of cron setup by the development team, it has caused the process hanging and not ended properly. According to them, these processes can be killed if still hang after 12 hours.

Any process which run in server will have start time (STIME). You can check this by using ps command. In this case, following result will appear:

$ ps aux | grep php
root      1399  0.0  0.0  61188   740 pts/2    S+   10:10   0:00 grep php
user1  2697  0.0  0.0 100664  8340 ?        Ss   Jul04   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1  5551  0.0  0.4 171052 78832 ?        Ss   Jun25   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1  9913  0.0  0.5 174636 82392 ?        Ss   Jun22   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 11961  0.0  0.7 223276 131060 ?       Ss   May25   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 16455  0.0  0.4 171564 79420 ?        Ss   Jun24   0:01 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 17474  0.0  0.5 182060 90016 ?        Ss   Jun18   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 20094  0.0  0.6 206636 114588 ?       Ss   Jun03   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 22555  0.0  0.7 213548 121476 ?       Ss   May30   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 24670  0.0  0.7 214572 122320 ?       Ss   May30   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 28200  0.0  0.7 220204 127988 ?       Ss   May26   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 30832  0.0  0.4 170284 78168 ?        Ss   Jun25   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 30837  0.0  0.4 170114 88508 ?        Ss   23:20   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php
user1 30848  0.0  0.4 120439 80770 ?        Ss   12:20   0:00 /usr/local/bin/php /home/user1/cron/sync2server.php

Continue reading “Linux: Kill Process based on Start Time (STIME)” »