5

I think I have a shell script (launched by root's crontab) that's stuck in a loop. How do I list running scripts and how can I kill them?

I'm running Ubuntu 9.04, but I imagine it's similar for all *nix systems...

Nick
  • 4,503
  • 29
  • 69
  • 97

4 Answers4

12

ps -ef will show you list of the currently running processes. Last field is the process name and parameters. Find the process you are looking for, and look at the 2nd column. 2nd column is process id or pid.

Then do kill -9 <pid> to kill that particular process.

solefald
  • 2,301
  • 15
  • 14
  • So what's the 9 for? It seems to work without it.... – Nick Apr 22 '10 at 23:31
  • 4
    @Nick: Normally kill sends a `SIGTERM` to the process, allowing it to shut down appropriately. Adding `-9` sends a `SIGKILL` instead, causing it to shut down forcibly without any chance of cleanup. See the `signal(7)` man page for some more details. – Ignacio Vazquez-Abrams Apr 22 '10 at 23:35
  • It's an equivalent of "force". Meaning nothing could block the kill command. – solefald Apr 22 '10 at 23:36
  • 2
    Except being in the middle of kernel code. Not even `SIGKILL` can interrupt that. – Ignacio Vazquez-Abrams Apr 22 '10 at 23:39
  • 2
    That's what the power buttons for... ;) – Nick Apr 23 '10 at 01:11
  • Some references: [When should I use kill -9?](http://aplawrence.com/SCOFAQ/FAQ_scotec6killminus9.html), [kill -9](http://speculation.org/garrick/kill-9.html), [Useless use of kill -9](http://sial.org/howto/shell/kill-9/) – Dennis Williamson Apr 23 '10 at 02:32
8

If you want a more stripped down version with better ASCII art (in my opinion I suppose) you can do

pstree -p
roknir
  • 181
  • 1
2

ps auxfwww will give you an ASCII art tree diagram of all the processes running on the system. From there it's just a matter of tracing down from the cron daemon and running kill against the appropriate PID.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
1

Or just good old top command, which will show a toplist of most resource-hungry processes.

Johan
  • 756
  • 5
  • 20