0

I have some scripts which spawns multiple processess to tasks in background. Most of them terminates but few of them does not terminates on finishing the task.

The number of these types of processes keeps on increasing and now they are consuming a big portion of server's resources.

They all have a status of Sl How can I kill all of them at once? Like, I want to run a cron which will kill and delete all these processes from system after a finite amount of time.

Manish Gupta
  • 113
  • 6

1 Answers1

2

This command works on my system to kill vi processes with the state "S". Change S to S1 and the process name regex pattern to whatever to get what you need.

ps ah -o pid,state,command | egrep "^.+\ S\ vi$" | cut -f1 -d' ' | xargs kill -KILL

Crontab:

00 01 * * * ps ah -o pid,state,command | egrep "^.+\ S\ vi$" | cut -f1 -d' ' | xargs kill -KILL

I suggest you look into something more elegant, like building something into your existing scripts to deal with hanging processes or figuring out why they don't exit, etc...

Ryan Babchishin
  • 6,160
  • 2
  • 16
  • 36