以下通过两种方法来根据进程名称获取pid
方法一
最简单的方法是使用 pidof 命令
用法:pidof process_name
示例
官网的详细用法如下:
NAME
pidof -- find the process ID of a running program.
SYNOPSIS
pidof [-s] [-c] [-n] [-x] [-m] [-o omitpid[,omitpid..]] [-o omitpid[,omitpid..]..] program [program..]
DESCRIPTION
Pidof finds the process id's (pids) of the named programs. It prints those id's on the standard output. This program is on some systems used in run-level change scripts, especially when
the system has a System-V like rc structure. In that case these scripts ar