Wednesday, January 26, 2011

How do I list currently running shell scripts?

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...

  • 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.

    Ignacio Vazquez-Abrams : `kill -9`? You're new, aren't you.
    solefald : heh... i am more old school than new...
    Nick : So what's the 9 for? It seems to work without it....
    Ignacio Vazquez-Abrams : @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.
    solefald : It's an equivalent of "force". Meaning nothing could block the kill command.
    Ignacio Vazquez-Abrams : Except being in the middle of kernel code. Not even `SIGKILL` can interrupt that.
    Nick : That's what the power buttons for... ;)
    Dennis Williamson : 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/)
    From solefald
  • 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.

    Nick : Thanks- this way was easier in this case since I could follow the tree down from the cron daemon.
  • If you want a more stripped down version with better ASCII art (in my opinion I suppose) you can do

    pstree -p
    
    Nick : Cool, Thank you!
    From
  • Or just good old top command, which will show a toplist of most resource-hungry processes.

    From Johan

0 comments:

Post a Comment