O'Reilly logo

Wicked Cool Ruby Scripts by Steve Pugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Killing a Stuck Process

Killing a Stuck Process

killProcess.rb

Applications are wonderful additions to operating systems. But occasionally they get stuck and begin to cause a self-inflicted Denial of Service attack on your system. Some processes are very stubborn and take extra effort to completely kill. This wicked little script will intuitively identify the stuck processes and automatically terminate them. How's that for avoiding additional manual work?

The Code

 #!/usr/bin/ruby
 max_time = 300
 ps_list = `ps h -eo cputime, pcpu, pid, user, cmd`

 list ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required