Linux shell script implementation kills processes based on process name

Source: Internet
Author: User

Miss the task Manager under Windows, ah, what to look at the pleasing of the program mouse points can be killed.

Today in the Firefox browser to browse the Web page, the interface instantly stuck, nothing can point, test, only switch to command line interface (CTRL+ALT+F1) to respond, cut back to the text interface Ctrl+alt+f7) or stuck. PS: Other keys feel like the failure of the general, very helpless to say ...

Walk in a daze at the command line interface, is going to force shutdown, suddenly found a previously written shell script, the function is to give a process name, will be the associated process ID all kill off.

The shell script source code is as follows:

#!/bin/sh# kill process According to process name if [$#-lt 1]then  echo "Missing parameter: procedure_name"  exit 1fi process= ' Ps-ef|grep $1|grep-v grep|gr Ep-v Ppid|awk ' {print $} ' for I in $PROCESSdo  echo "Kill the" process [$i] "  kill-9 $idone

Effect:

If you feel that the above code is complex, you can use the following sentence directly to achieve.

Ps-ef | grep procedure_name | Grep-v grep | awk ' {print $} ' | Xargs kill-9

Reference address

Linux shell script implementation kills processes based on process name

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.