I
I
Ivan Ivanov2020-02-20 20:02:14
Debian
Ivan Ivanov, 2020-02-20 20:02:14

How to kill processes that are older than half an hour in, say, Debian?

I use headless chrome along with Puppeteer in cron, and sometimes it all hangs and processes remain in memory. Is it possible to beat them somehow? To kill all such processes I use

kill $(ps aux | grep 'node_modules' | awk '{print $2}')

Is it possible to somehow extract the start time of the process from ps aux, and beat only processes older than a certain time, for example, launched more than half an hour ago?
Also, due to the clogging of memory by such processes, cron stops working. Can something be done about it?
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Radjah, 2020-02-21
@Radjah

Get confused with cgroup and nail down the PID list, for example, otherwise you can do business like that.

K
ky0, 2020-02-20
@ky0

Nail everything in a row along the crown. Cheap and reliable.

H
hint000, 2020-02-21
@hint000

When starting the process, create a pid file (for example, adding pid to the file name so that they can all be in the same folder). To kill, search by creation time of pid files.

S
Saboteur, 2020-03-07
@saboteur_kiev

ps -e --sort lstart -o pid=,cmd=,lstart=
you can parse the start time of processes and kill them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question