根据进程名获取进程 PID

[root@VM-0-12-centos ~]# ps -ef | grep postmaster | grep -v grep 
postgres 1025 1 0 Oct02 ? 00:00:25 /usr/pgsql-14/bin/postmaster -D /var/lib/pgsql/14/data/
[root@VM-0-12-centos ~]#

根据进程 PID 获取进程名

[root@VM-0-12-centos ~]# ps -p 1025 
PID TTY TIME CMD
1025 ? 00:00:25 postmaster
[root@VM-0-12-centos ~]#
[root@VM-0-12-centos ~]# ps -p 1025 -o comm=
postmaster
[root@VM-0-12-centos ~]#