DISQUS

DISQUS Hello! Tech-Recipes is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Tech-Recipes

Cookbook of Tech Tutorials
Jump to original thread »
Author

Kill the undesired UNIX processes in one go | UNIX | Tech-Recipes

Started by qdideas · 9 months ago

No excerpt available. Jump to website »

8 comments

  • Sorry to appear thick, but could you give an example of processname-patern
    thanks for posting this great help jproctor
  • That's a good question. Using grep has a brief but steep learning curve. Most UNIX commands do. Once you get the basics, you can put grep to powerful use.

    In the most basic usage, grep will search through text looking for the search string. If you want to look for commands containing the string 'http' you would simply use:

    ..... | grep http | ....


    Grep stands for global regular expression parser and is a magnificently powerful tool. The important thing to take out of that mouthful is 'regular expression' which is a formal language for representing elaborate wildcards for searching. For example, a period matches any single character, so .at would match bat, cat, rat, and so on. Used in a grep statement, it would match that regular expression anywhere in the line, so it would also match brat and bats. Regular expressions would be a great idea for a series of rec.pes.
  • i think you might want to look into the killall command
  • a kill -9 doesnt give the process the possibility to clean up; to exit "voluntarily". can screw up its data.

    always try a kill (without -9) first
  • You can use the following command :

    kill -9 `ps -ef | grep <process-name> | grep -v grep | awk '{print $2}'`

    Just make sure that you keyin the correct process name in the above command.
  • <ul id="quote"><h6>jproctor wrote:</h6>Sorry to appear thick, but could you give an example of processname-patern
    thanks for posting this great help jproctor</ul>

    you can use pgrep and pkill
  • Hi,
    PID TTY COMMAND
    2345 ? 0:00 msgcntl //
    4977 pts/tc 0:00 ps
    3807 ? 0:00 spectrum
    3813 ? 0:00 msgcntl //
    3802 ? 0:00 printmgr
    3814 ? 0:00 ssmcntl//
    3810 ? 0:00 ptrcntl//
    3815 ? 0:00 ssmcntl//
    3811 ? 0:00 termcntl//
    3817 ? 0:00 ssmcntl//
    3816 ? 0:00 pccntl//
    3798 ? 0:00 rsetcntl//
    2215 pts/tc 0:00 sh

    <font color="blue">In the above scenario, I have to kill all the process except ps and sh . How to do that ?</font>

  • egrep -v "ps|sh|PID" file | awk '{print $1}' | xargs kill

Add New Comment

Returning? Login