kill using the ps command

hello, can anyone help me with a script that checks the status of processes and "kills" the process that's hanging? I mean I'm aware of the commands but I'm confused on how to put them all together... thanks! :slight_smile:

What is the criteria of the term "hanging" in your context?
100% CPU? ( thats not hang however), running for particularly longer time? or do you mean to say "zombie" process?
How do you going to determine that with "ps" ?!!

ok I might have confused you a bit with the words I used, let me rephrase that. I need a script that uses the ps command to display the programs which uses the CPU the most and then kill the highest one...

As worded, such a script is madness.
A glance round a few sample systems which are running normally found the top CPU users to be the: disc daemon, a database engine; a background report. None of these are rogue processes. Also, on a multi-CPU system it is quite normal for a process to use 100% of one CPU.

Because there is much variation in the "ps" command, please post the exact Operating System and version you are running and what Shell you use.
Please also post a detailed tried-and-tested example of your "ps" command which identifies the faulty process(es).

There will always be a process which is using the maximum of the CPU at a given time.

I think it might be a good idea to first find out the processes which are taking a lot of CPU space and can be killed. Then there can be a single line command that can work.