Linux acquires JMeter PID and kill with Boot

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

With the known process name (name), the interactive Shell gets the process PID in a number of ways, typically by using grep to get the PID (where the-v grep is added to avoid matching to the grep process):

ps -ef | grep "name" | grep -v grep | awk ‘{print $2}‘

Or do not use grep (where the initials are added [] to avoid matching the process to awk itself):

ps -ef | awk ‘/[n]ame/{print $2}‘

If you use only the x parameter, the PID should be in the first place:

ps x | awk ‘/[n]ame/{print $1}‘

The simplest way is to use pgrep:

pgrep -f name

If you need to find the PID and kill the process, you can also use Pkill:

pkill -f name

If the program is executable, you can use pidof directly.

pidof name

Get Jmeter_pid

[[email protected] ~]# ps -ef | grep "jmeter" | grep -v grep | awk ‘{print $2}‘    184061840818442

Writing the Shell

#!/bin/bash#jmeter kill and startecho -e ‘\033[32m--------Jmeter---------------\033[0m‘echo "kill掉jmeter-server 进程................... \n"kill -9 `ps aux | grep jmeter | grep -v grep | awk ‘{print $2}‘`sleep 3cd /root/tools/apache-jmeter-3.3/bin/echo "启动jmeter-server"nohup ./jmeter-server &echo -e ‘\033[32m------------欢迎使用-----------------\033[0m‘

Linux acquires JMeter PID and kill with Boot

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.