Killing all the process of a particular enviroment

Hi Folks,

I have the below command that will kill all the process of an environment,
lets say if I have reached to the location cont directory under which I want to kill multiple process so the command will be ....

kill -9 `ps -ef | grep cont | grep -v grep | awk '{print $2}'`

Now please advise is there any better alternative of the above command that is more efficient .:confused:

Second thing is that I want to kill the multiple process in such an order such that once which started first shoulbe get killed as it is in ascending order and should show in console also while doing., please advise.:eek:

kill -9 `ps -ef | awk '/cont/ {print $2}'`

If you want to kill the processes in sorted order, you might want to you sort between ps and awk command

kill -9 `ps -ef | awk '/[c]ont/ {print $2}'`

The [ ] trick prevents a match of the own process (i.e. awk's argument)
Another method

pkill -f cont

A normal kill is normally better.
With a ps -ef output we perhaps could suggest a more precise match.

Can you please explain in detail about the meaning that ...The trick prevents a match of the own process, i haven't grasp that..!Thanks

The two regular expressions cont and [c]ont are equivalent and will result in the same set of lines being selected. The difference is that the 2nd version will not match it's self so even thought awk '/[c]ont/...' appears in the ps listing it will not be matched.