I just finished a web scraping app made with puppeteer and node, and at this point in time it is very unstable due to relatively low to none experience with puppeteer (further debugs on it crashing is coming up). Sometimes, when running multiple instances of that app, one of them crashes and that node process won't terminate and it will stay up forever or until I manually kill it.
I am using: ps -e | grep node
to detect all node processes and: pkill -f node
to kill every process. Digging a bit in, I discovered this: ps -eo pid,comm,lstart,etime,time,args
, that returns every Linux process. The time
parameter returns the elapsed time of the process. Now my question is : is there a way to kill only those node processes of which the elapsed time is greater than 5 minutes?
A normal run of the puppeteer script usually does its job in around 3-4 minutes, depending on the amount of information it has to scrape.
Please please help! Thank you!