Shell Get Process PID

Source: Internet
Author: User
Tags pkill

There are some differences between the interactive shell and shell scripts of Linux, mainly because of the existence of a separate running process, so there is a difference between the acquisition process PID.

Interactive Bash Shell get process pid
#在已知进程名 (name), the interactive Shell gets the process PID in a number of ways, typically by using grep to get the PID method (add-v grep here to avoid matching to the grep process): Ps-ef | grep "Name" | Grep-v grep | awk ' {print $} ' #或者不使用 grep (where the initials are added [] to avoid matching to the process of awk itself): Ps-ef | awk '/[n]ame/{print $ ' #如果只使用 x parameter then the PID should be in the first position: PS x | awk '/[n]ame/{print $ ' #最简单的方法是使用 pgrep:pgrep-f name# If you need to find the PID and kill the process, you can also use pkill:pkill-f name# if it is an executable program, you can directly make With pidofpidof name

Learn the shell address

Https://www.yiibai.com/shell/unix-special-variables.html

Http://wiki.jikexueyuan.com/project/shell-learning/gorgeous-printf-output.html

Shell Get Process PID

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.